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

Respawning only works once ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago

So i want 8 seconds to respawn and it works only once, then it just stays dead.

local time = 8

    game.Players.CharacterAutoLoads = false
            game.Players.PlayerAdded:connect(function(player)
                game.Players.CharacterAutoLoads = true
                    repeat wait() until player.Character
                game.Players.CharacterAutoLoads = false
            player.Character.Humanoid.Died:connect(function()
        wait(time)
    player:LoadCharacter()
end)
end)

problem ? No errors.

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

Your problem is that you're only setting up the events for one humanoid, which gets removed the first time you respawn.

To fix this, we'll have to use a CharacterAdded event to run you're function for every character that is loaded.

local respawnTime = 8

game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.Died:connect(function()
            wait(respawnTime)
            player:LoadCharacter()
        end)
    end)
    wait()
    player:LoadCharacter()
end)

NOTE: It's a good habit to effectively tab your code. It will make it much easier to read and spot errors.

0
Thank you! Bulvyte 388 — 8y
Ad

Answer this question