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

How can you make a script tell if a user has died or been respawned?

Im making a hotel room board and it will check if the user has left or has been respawned and idk how to check for that.

3 answers

The humanoid has its own function that runs when the player (humanoid) dies.

Checking if the humanoid died with a local script

local player = game:GetService("Players").LocalPlayer
local humanoid = player:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
    --Do stuff
end)

Checking if the humanoid died with a script

--This script is parented to ServerScriptService

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		if humanoid then
			humanoid.Died:Connect(function()
				--Do stuff
			end)
		end
	end)
end)

Define all the players in a local script. Then do a DiedFunction, then make a Frame visible. Thats pretty much it Not going to give script.

 game:GetService('Players').PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) 
print('Character has been respawned.') 
Character.Humanoid.Died:connect(function() 
print('Character has been killed.') 
end) 
end) 
end)

1 comment

0

Your code isn't indented which makes it hard for anyone to read

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