Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I fix this spawning problem?

Asked by
Yeevivor4 155
10 years ago
   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

Log in to vote
1
Answered by
RedCombee 585 Moderation Voter
10 years ago

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
0
I defined what my map is, but I still can not spawn to the bricks. Yeevivor4 155 — 10y
0
When does this script run? Does it run during a round or something? RedCombee 585 — 10y
0
I can post up the whole script. Yeevivor4 155 — 10y
0
Where exactly does it stop working? RedCombee 585 — 10y
View all comments (2 more)
0
It doesn't work when the character is suppose to move into position where the brick is. Yeevivor4 155 — 10y
0
I solved the spawning problem. The only thing is the team chooser. Yeevivor4 155 — 10y
Ad

Answer this question