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

What is the best way of respawning all players?

Asked by
L43Q 48
6 years ago

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

Log in to vote
2
Answered by 6 years ago
Edited 5 years ago
for _,v in pairs(game:GetService("Players"):GetPlayers()) do --no need to check if its a player
    v:LoadCharacter()
end
1
Ah, thanks. I never knew GetPlayers existed but it will definitely make it more efficient L43Q 48 — 6y
0
+ 1 for teaching someone about :GetPlayers() Ziffixture 6913 — 5y
Ad

Answer this question