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

Respawning only works once ?

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

✓ Accepted answer

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.

1 comment

0

Thank you!

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