Description of what I need it to do: In my game, you start off in the lobby, which has its own team that is Medium stone grey. After a while the players in the lobby change to either red or blue randomly. Then they teleport to the map with random spawns. I have them spawning on givers... to give them they necessary tools they need, but there are some occasions to where they wouldn't receive the tools. TO THE POINT: The script is being copied from server storage and pasted into workspace at the approximate time I need the players to receive their tools. The script needs to recognize players already in the game/ on the red and blue team and give them the tools. Instead of using a lousy button giver...
Here is the script:
weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()} for _, v in pairs(game.Players:GetChildren()) do if v.TeamColor == BrickColor.Red then weapons[1].Parent = v.Backpack end if v.TeamColor == BrickColor.Blue then weapons[math.random(1,2)].Parent = v.Backpack end end wait(3) script:Destroy()
Notice: Before attempting to fix it read description above script (Entirely)
If its a server script and the parent of the script is workspace then your code will be:
wait(3) for _, player in pairs(game.Players:GetChildren()) do weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()} if player.TeamColor == BrickColor.Red then weapons[1].Parent = player.Backpack end if player.TeamColor == BrickColor.Blue then weapons[math.random(2, 3)].Parent = player.Backpack end end wait(3) script:Destroy()
if its in a localscript and its on the backpack your code will be:
local player = game.Players.LocalPlayer spawn(function() local weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()} if player.TeamColor == BrickColor.Red then weapons[1].Parent = player.Backpack end if player.TeamColor == BrickColor.Blue then weapons[math.random(2, 3)].Parent = player.Backpack end wait(3) script:Destroy() end)