Im trying to make a round system that gives the players tools in startergear but
not sure how to make the tool get added to starter gear when a player joins during the round.
Ive try using Players:GetChildren() but it only gives the tool to players that are in the game.
What should i use to make it work when a player joins the round.
You can do something simple like have a function for giving gear to players, and have it run on a for loop, and run when a player joins. Like this:
local PS = game:GetService("Players")
local RoundStartEvent = game:GetService("ServerStorage"):WaitForChild("RoundStartEvent") --Bindable Event in ServerStorage which is fired when the round starts (should be fired by another script that handles rounds)
local function giveWeapons(plr)
--Code to give the player the appropriate weapons
end
PS.PlayerAdded:Connect(function(plr)
giveWeapons(plr)
end
RoundStartEvent.Event:Connect(function()
local plrs = PS:GetPlayers()
for i,v in pairs(plrs) do
giveWeapons(v)
end
end
Edit: You can also have a function firing whenever a player dies and respawns.
You can have a variable in ServerStorage that dictates whether the round is started or not.
Here is a script edited to by like that:
local PS = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local RoundOn = SS:WaitForChild("RoundOn") --A BoolValue Object which is set by another script or module handling the rounds.
local RoundStartEvent = SS:WaitForChild("RoundStartEvent") --Bindable Event in ServerStorage which is fired when the round starts (should be fired by another script that handles rounds)
local function giveWeapons(plr)
--Code to give the player the appropriate weapons
end
PS.PlayerAdded:Connect(function(plr)
if RoundOn.Value then
giveWeapons(plr)
end
end
RoundStartEvent.Event:Connect(function()
if RoundOn.Value then
local plrs = PS:GetPlayers()
for i,v in pairs(plrs) do
giveWeapons(v)
end
end
end
I also changed it so that it doesn’t give the round weapons if the variable is set incorrectly, so make sure to set the BoolValue to true before firing the BindeableEvent (in this case, obviously you could put all of this in one module or script if you wanted to.