Load player character to dummy - lua

I'm pretty new to scripting but I'm trying to make a lobby system. Basically when players join they are assigned to the 4 dummies (so 4 players max). So the dummies look like the players. I'm getting very confused looking at the Roblox documentation followed by little scripting experience experience.
I want to:
First delete any dummys that are already loaded
Assign players to the dummies as they join then remove dummies as they leave
Duplicate the dummies from replicated storage and parent them to the Workspace.
Just looking for some guidance please don't write an entire script as I'm trying to use this as a learning tool.
Hers the code so far and now my head hurts haha
local function characterRig()
for i,player in pairs(game.Players:GetPlayers()) do
local dummy = game.ServerStorage["Dummy"..i]
player.CharacterAutoLoads = false
player.Character = dummy
local playerHumanoid = player.Character.humanoid
playerHumanoid:GetHumanoidDescriptionFromUserId()
dummy.Parent = workspace
end
end
game.Players.PlayerAdded:Connect(characterRig)
game.Players.PlayerRemoving:Connect(characterRig)

Related

I need to make a wave system for every player

I have a few islands, where players spawn, and I need to make a wave(round like in TD games) system for every player, and, when a player leaves and then joins the game, everything should start from a wave, where the player finished. I guess I know how to save data but I really don't know how to make a separate wave system for every player, I mean, where I have to save the value of the wave number. I'm a total noob in everything so I really don't understand how starter pack changes work and server storage also. So I would be rlly happy if anyone could help with it.
Also, I know that there are module scripts and they may help here, but I don't know how can I use it here.
I have a spawner of enemies and I need to change it for the wave system
local marine = rs.Enemies.OnePiece.Marine2:Clone()
local anim = rs.EnemiesScripts:FindFirstChild("Animation"):Clone()
local move = rs.EnemiesScripts:FindFirstChild("Movement"):Clone()
local hpBar = rs.BillboardUi.HpBar:Clone()
hpBar.Parent = marine
move.Parent = marine
anim.Parent = marine
marine.Parent = workspace.Islands:WaitForChild("1").Bodies:WaitForChild("enemies")
marine.HumanoidRootPart.CFrame = marine.Parent.Parent.Parent:FindFirstChild("enemySpawner").CFrame * CFrame.new(0,10,0) * CFrame.Angles(0,3.2,0)````

How to create a hitbox that lets players through if they have enough money and keeps them out when they don't have enough? - Roblox

Been trying for a while now, not sure how to create a way to block players who don't have enough money to enter a zone and let players through who have enough money if not more.
I have a fully transparent part that i would like to act as the hitbox. I also have leaderstats set up and functioning.
If anyone could help, would be much appreciated :)
This is a great use-case for PhysicsService's CollisionGroups.
You can set up a CollisionGroup where objects in one group do not collide with those in another. It's often used for engine optimizations when a lot of objects simply don't need to check whether they need to collide with others, but you can definitely use them for this as well.
For this case, we'll set the door to be in one collision group, and every player that has unlocked the door will be in another. When they touch the door, it will check how much money they have, and if they have enough it will add each part of their character model into the unlocked group. This will allow their character model to phase right through the door.
So, in order to make this work, I added a Script to the Part that I was using for the door, and I added this code :
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local COST_TO_ENTER = 10 -- update with the actual cost to open the door
local DOOR_GUID = game.HttpService:GenerateGUID()
local LOCKED_DOOR_ID = "LockedDoor" .. DOOR_GUID
local ALLOWED_PLAYERS_ID = "UnlockedPlayers" .. DOOR_GUID
-- find the door that we'll be unlocking
local door = script.Parent
-- create a collision group for the door, and another for players that have unlocked it
PhysicsService:CreateCollisionGroup(LOCKED_DOOR_ID)
PhysicsService:CreateCollisionGroup(ALLOWED_PLAYERS_ID)
-- add the door to the door's collision group
PhysicsService:SetPartCollisionGroup(door, LOCKED_DOOR_ID)
-- make it so that character models in the unlocked group don't collide with the door
PhysicsService:CollisionGroupSetCollidable(LOCKED_DOOR_ID, ALLOWED_PLAYERS_ID, false)
-- listen for when players touch the door to see if we should unlock it
door.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
if player.leaderstats.Money.Value >= COST_TO_ENTER then
-- if they have enough money, add their character model to the allowed player collision group
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, ALLOWED_PLAYERS_ID)
end
end
-- TODO : update the visuals of the door client-side so that players know that it is unlocked for them
end
end
end)
-- clean up if the door is getting deleted
door.Destroying:Connect(function()
PhysicsService:RemoveCollisionGroup(LOCKED_DOOR_ID)
PhysicsService:RemoveCollisionGroup(ALLOWED_PLAYERS_ID)
end)
This system doesn't persist whether a player has unlocked the door. So if your character dies, they may need to have enough money to get back in again. But it would be fairly simple to add a receipt system that keeps track which players have unlocked it, and re-add character models to the collision group upon respawn.
Not Enough Money
Enough Money
Every time the money changes, you would also change the CanCollide property of the hitbox. For example:
money.Changed:Connect(function()
hitbox.CanCollide = money.Value < 1024
end)
Here, the < operator will return true if the value of money is smaller than 1024, false otherwise. So if the amount of money is small, the block will collide with the player (not letting him/her in), but otherwise it doesn't.
You would do that in the client so that it only applies to that specific client, not all clients.
Protecting it from cheaters isn't necessary in this case, Roblox characters themselves are exploitable. If you're making an anti-cheat, you can make these zones impossible to enter by teleporting the player to their previous position if they enter when they shouldn't be able to.

I'm trying to get "leaves" to produce a rustling noise in a Roblox game by monitoring all child parts of the script

Using the Child-monitoring script #Kylaaa helped me with in another question, I've spent hours on this, altering the core functionality from healing and disappearing bricks to play a parent sound when the player "walks through the leaves". I've been studying various aspects of the problem ('IsA', 'TouchInterest', 'If...then', Classes, Operators, etc.), and done various things, such as altering my script to look at the name of touched objects instead of their classes, but I've had no luck getting the sound to play.
-- create a helper function to access the brick and the thing that touched it
function OnTouched(thing)
local active = false --start with this debounce variable off so that the function will run the first time
return function(target) --provides actual target of the event
if active then return end -- do not do the animation again if it has already started
local player=thing.Parent:findFirstChild("Humanoid") --determine if it's humanoid
if player then --if it is, then
active = true --toggle to prevent function from running again simultaneously
script.Parent:play() --play rustling leaves sound
wait(1)
active = false -- reset so function can be used again
end --end of if statement
end
end
-- loop over the children and connect touch events
local bricks = script:GetChildren()
for i, brick in ipairs(bricks) do
if brick:IsA("Part") then
local onTouchedFunc = OnTouched(brick)
brick.Touched:Connect(onTouchedFunc)
end
end
This is a shot of the leaf litter I want to add the rustling sound to. I also have the same problem with the vines on the left side.
Vines:
All leaves are 'MeshParts' with 'SurfaceAppearance' inside, and are Anchored and CanTouch but not CanCollide. I tried turning on CanCollide but it didn't help.
Dense Leaf patch properties:
Surface Appearance properties:
I had tried "if brick:IsA("Model" or "MeshPart") then"
and
"if brick.Name=="Dense Leaf patch" or "SurfaceAppearance" or "DenseLeafPatch" then"
but neither of those worked.
I then noticed that a TouchInterest wasn't generated by Roblox, and I learned that you can neither copy nor duplicate TouchInterests to use where you need them (they're not there for developers, according to a message in the DevForum).
I originally had 1-3 leaves 'MeshPart's in separate 'Model's, but then made a single, invisible part (name: TouchInterest), CanTouch not CanCollide, that was large enough to cover almost all of the physical area of the instances, and put all of the MeshParts into that part. Then, I altered the script to just look for 'Part's. As a result, a TouchInterest does get generated during run-time.
This is all of the stuff involved in the group "leaves", with the sound, then the script, the containing part, then all the leaves inside as children of the script.
Sound's properties:
No errors for this were in the Output.
I feel like there's something simple I don't understand. Do I need several small parts (instead of the one large one) encompassing groups of leaves? Please help!
I figured out the problems.
On line 6, I used "thing" when I should've used "target".
On line 9, I forgot to capitalize "Play".
On line 10, I needed to make the wait 2 seconds instead of 1.

need help detecting game lighting in my lua script

I am trying to make a script, in Lua code, that detects the level of lighting in my game. I am pretty new to Lua so as far as I know lighting in the game is a number (2, 10, 5).
if game:GetService("Lighting").Brightness < 1 then
game.StarterGui.ScreenGui.output.Text = "You are getting cold";
end
I am not sure if it is just not detecting game:GetService("lighting").Brightness as a number or if the game does not know what game.StarterGui.ScreenGui.output.Text is. I've testing this multiple times, making small alteration every time, but most of the time I got no error. With the code now there is no error message.
Do not use game.StarterGui.
StarterGui is what gui is put inside a player's PlayerGui when they join. Players do NOT see StarterGui.
Instead:
game.Players.PlayerAdded:Connect(function(plr)
if game:GetService("Lighting").Brightness < 1 then
plr.PlayerGui.ScreenGui.output.Text = "You are getting cold";
end
end)
(player).PlayerGui is the gui the player sees. StarterGui will not auto update or modify the game's players' guis when it is changed.
If you have any more questions feel free to ask them with a comment! ^-^
Roblox lua documentation:
https://www.developer.roblox.com/en-us

What is ROBLOX Lua scripting? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I really dont understand what it really even is. Is it just normal scripting or something else?
Lua is a fairly well known and often embedded scripting language.
However, if you're after some basic "getting starting" information on Roblox scripting, check out the Roblox Wiki. (The tutorial's section would probably be of specific interest.)
Lua is a well known scripting and programming language that is lightweight and easy to learn. Many games have embedded it, including Garry's Mod (GMod) and World of Warcraft.
ROBLOX uses Lua to actually create games. Most of the features you see in ROBLOX (like the GUI and building tools) are actually coded in Lua.
I'd recommend seeing games by Anaminus, VolcanoINC and Telamon to see what you could do with Lua.
Lua is a scripting language somewhat similar to Java. Infact, I recall there being a Javalua blend as a scripting language in itself. Lua is probably the easiest scripting language to learn and work with. Its functions are fired by changes specified such as script.Parent.Value.Changed:connect(functionnamehere)
Parents are what the script or item specified is in.
Variables work like this:
v = script.Parent.Value
or
d = game.Workspace.ScriptFireValue.Value
If a ROBLOX Solo Game is the source and v's script.Parent's name (script.Parent.Name) is ScriptFireValue then v is equal to d.
The language also includes loops that are recognizable like
lua: while true do
vbs: do while/Loop
java: do while
'for' is a limited loop where it only loops for a certain amount of times.
exe.
for i = 1, 10 do
game.Lighting.TimeofDay = game.Lighting.TimeofDay + 1
end
This part of the script will run 10 times before passing on. when u have the part 1 - 10 or 1, 10.
The 'end' comes after anything highlighted in blue.
Things highlighted will be:
for [whatever's in here will not be highlighted] do - Both words only count for one end.
while true do
while [Something in here that exists or is a value] do - Both words only count for one end.
function()
if [something exists or is a value] then - Both words only count for one end.
else -- Used when the if statement before it is false. When used the 'if' and the 'else' count for one end.
elseif -- Used when the if statement before it is false but also calls for another if statement. When used the 'if' and the 'elseif' count for one end.
I think a few more.
Here's an example script I'm writing off the top of my head. The source I'm going off of is ROBLOX's Build/Edit mode in-game.
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends if
end -- ends for - do
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
That script if not obvious identified the player who clicked. (clicker). Btw the argument 'clicker' would be identified the cause of the function to be fired. So the cause is because a button was 'Clicked'. So 'clicker' retrieves the person who initiated that. Therefore identifying if the player is a certain person which would allow the process to continue. So if the player's name is coolboy10000 then it will gather all the players and kill them each.
To put a security on that button to where if the player is not coolboy10000 then the player will be killed you could do this:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
If there are multiple people to allow to do this function you could do:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" or "coldnature" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
Or if there is a specific person who should have a separate punishment:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" or "coldnature" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
elseif clicker.Name == "Person299" then
clicker.Head.Position = clicker.Torso.Position
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else and elseif - then
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
Yeah that's just the basics :/
There are tutorials out there. Mostly on ROBLOX free models. I say you should study some free scripts and learn how they work and stuff. This is just the basics. There is a tutorial on ROBLOX. Just search in Free Models scripting tutorials. Some dude wrote in scripts how to script. It's pretty long to read but that's how I learned.
Roblox is a gaming website where the users make the games using "Roblox Studio". It's almost like a super complex virtual Lego. To interact with your parts(anything in your game) you make scripts that are written in the language "Lua".
Roblox Lua is Lua 5.1 in Roblox's Data Model.
Roblox Lua Scripting is the act of writing in a script in Roblox Studio.
Their scripts are actually objects with embedded code inside of them. They're placed inside of roblox's basic data model and are used for creating and controlling objects, data, and therefore game-play.
I will not repeat what others have said, and say something else instead.
Unlike vanilla lua, ROBLOX lua (also known as rlua) is a modified version of lua.
ROBLOX has implemented different kinds of c and l closures such as tick, wait, delay, and so on, which is why it is a modified version of lua.
Roblox Lua scripting is an embedded coding language to add features to your game. It is easy to learn and is a loose interpretation of modern day game programming. Its an overall great language and I highly recommend it!
https://roblox.fandom.com/wiki/Project:Home
https://devforum.roblox.com/

Resources