while true do wait(5)--intermission maps = game.ServerStorage.Maps:GetChildren() map = maps[math.random(1, #maps)] map:Clone().Parent = game.Workspace blue = 0 red = 0 local teamplay = game.Players:GetChildren() for i = 1,game.Players.NumPlayers do local ran = math.random(1,game.Players.NumPlayers) if blue == red then -- if they are the same it is randomely generated br = math.random(1,2) if br == 1 then teamplay[ran].TeamColor = BrickColor.new("Bright blue") elseif br == 2 then teamplay[ran].TeamColor = BrickColor.new("Bright red") end elseif red >= blue then teamplay[ran].TeamColor = BrickColor.new("Bright red") elseif blue >= red then teamplay[ran].TeamColor = BrickColor.new("Bright blue") end end for _,player in pairs(game.Players:GetPlayers()) do if player.Character then spawns = map.Spawns:GetChildren() player.Character:MoveTo(spawns[math.random(1, #spawns)].Position) end end wait(300)-- five minutes for i,player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character.Head:remove() player.TeamColor = BrickColor.new("White") end end end
I am wondering how to fix this. It seems like it doesn't work even though I've added spawns.
In the script, line 3...
spawns = map.Spawns:GetChildren()
You never set a variable for "map". The code looks fine otherwise.
And it appears that your script would run on the server before any player even joins the game, so the if statement would always fail.
You also only have one end where you need two. You have a loop and an if statement, but the if statement isn't actually necessary.
I suggest...
for _,player in pairs(game.Players:GetPlayers()) do chr = player:WaitForChild("Character") spawns = map.Spawns:GetChildren() -- Define "map" as a variable chr:MoveTo(spawns[math.random(1, #spawns)].Position) end