Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix this spawning problem?

   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.

1 answer

✓ Accepted answer

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

6 comments

0

I defined what my map is, but I still can not spawn to the bricks.

0

When does this script run? Does it run during a round or something?

0

I can post up the whole script.

0

Where exactly does it stop working?

0

It doesn't work when the character is suppose to move into position where the brick is.

0

I solved the spawning problem. The only thing is the team chooser.

This discussion is preserved as it was. New answers, comments, and votes are closed.