This script is for a game i'm making and it works up until the respawning all script. I don't believe there are any errors. If you could tell me why it is working I would really appreciate it. It is a script in script server service.
MoreThan2PlayersValue = game.ReplicatedStorage.MoreThan2PlayersYN
if MoreThan2PlayersValue.Value == true then
players = game:GetService("Players"):GetPlayers()
randomPlayer = players[math.random(1, #players)]
print("picked a random player")
end
for _,Player in pairs(game.Players:GetPlayers()) do
--Looping through all players
Player.TeamColor = BrickColor.new("Bright yellow")
print("teamed all baghead")
end
TheSurvivor = randomPlayer
game.Players.TheSurvivor.TeamColor = BrickColor.new("Bright green")
print("teamed the survivor")
for i,v in ipairs(game.Players:GetPlayers()) do
v:LoadCharacter()
end
print("attempted to respawn all players!")
while wait(1) do
if game.TheSurvivor.Humaniod.Health <= 0 then
for _,Player in pairs(game.Players:GetPlayers()) do
--Looping through all players
Player.TeamColor = BrickColor.new("Bright blue")
end
game.ServerStorage.StartAfter2PlayersJoin:Clone()
game.ServerStorage.StartAfter2PlayersJoin.Parent = game.ServerScriptService
script.Parent:Destroy()
end
end
(It makes it to the respawn part so I only need help on that part, I included the rest of the script just in case something in there is relevant to it not working.)

1 comment
line 20. ipairs? Why not just use pairs? It's possible that the script immediately runs into a nil value and stops loading every other player.