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

How can I fix this Death script?

This is a server script:

game.Players.PlayerAdded:connect(function(player) 
local died = false 
repeat wait() until player.Character 
local Humanoid = player.Character:WaitForChild("Humanoid")
Humanoid.Died:connect(function() 
died = true -- If player died, change variable 
end) 

player.CharacterAdded:connect(function(character) 
if died then -- If the player died then 
print(player.Name .. " has been resurrected!") 
died = false 

else -- If the player didn't die then 
print(player.Name .. " has been refreshed!") 
end 
end) 
end) 

It's meant to differentiate between when a player dies (respawns) and when a player reloads their character (refreshes) with :LoadCharacter (which is not dieing). However when a player dies it incorrectly reads "player has been refreshed" rather than "player has been respawned". How can I fix this?

1 answer

game.Players.PlayerAdded:connect(function(player) 
	local died = false 
	repeat wait() until player.Character 
	local Humanoid = player.Character:WaitForChild("Humanoid")
	Humanoid.Died:connect(function() 
		died = true -- If player died, change variable 
	end)
end) 

player.CharacterAdded:connect(function(character) 
	if died then -- If the player died then 
		print(player.Name .. " has been resurrected!") 
		died = false
	elseif died == false then
		print(player.Name .. " has been refreshed!") 
	end 
end) 

3 comments

0

"player" wasn't defined in the second paragraph, so I moved the end for the playeradded event to the end of the second paragraph, and... IT STILL SAYS REFRESHED WHEN I DIE! This is infuriating!

0

No need to thumbs down.

0

Sorry, it's just that it's clear this hasn't been tested and it's just a total waste of time.

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