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

how do i make a script that detects when the player dies and prints out value?

i.e if Player health == 0 then print('ded') end

2 answers

✓ Accepted answer

You can do this with the Humanoid.Died event.

Read more here

i.e

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			print(player.Name .. " has died!")
		end)
	end)
end)

1 comment

0

ty

Hey RealRexTeam,

The humanoid has a .Died event that you can use to detect when the player dies. I recommend just attaching it to the .CharacterAdded() function so that it runs at all times while the player is alive and it is well formatted that way. Here, I'll show you an example of it below.

####Script

local plrs = game:GetService("Players"); -- The players service

plrs.PlayerAdded:Connect(function(plr) -- PlayerAdded anonymous function with parameter of the player.
	plr.CharacterAdded:Connect(function(char) -- CharacterAdded anonymous function with parameter of the player.
		local hum = char:WaitForChild("Humanoid"); -- The humanoid in the Character.
		hum.Died:Connect(function() -- .Died anonymous function
			print("Humanoid has died.") -- Prints "Humanoid has died." 
		end) -- end for .Died function.
	end) -- end for .CharacterAdded function.
end) -- end for .PlayerAdded function

###Well, I hope I helped and have a nice day.

~~ KingLoneCat

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