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

What is the best way of respawning all players?

In my game, all players respawn after each round, using this loop

for i,v in pairs(game.Players:GetChildren()) do
	if v:IsA('Player') then
		if v.Character ~= nil then
			v:LoadCharacter()
		end
	end
end

While it almost always works flawlessly, on rare occasions this section of the script just seems to freeze. I don't get any errors, but the script doesn't move on after this point, and I know this because the script has a print before and after this loop.

Is there a better way of doing this so it always works? Am I doing something wrong?

Thanks for any help

1 answer

✓ Accepted answer
for _,v in pairs(game:GetService("Players"):GetPlayers()) do --no need to check if its a player
	v:LoadCharacter()
end

2 comments

1

Ah, thanks. I never knew GetPlayers existed but it will definitely make it more efficient

0
  • 1 for teaching someone about :GetPlayers()

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