Died (Event): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Camoy
Formatted
>JulienDethurens
No edit summary
 
(22 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{|
<onlyinclude>{{Event
|<onlyinclude>{{Event
|name = Died
|name = Died
|arguments =
|description = Fired after a Humanoid's health reaches 0.
|description = Fired after a Humanoid dies.
|object = Humanoid
|object = [[Humanoid]]
}}</onlyinclude>
|}}</onlyinclude>
 
|}
{{clear floats}}


== Description ==
== Description ==
Died event is triggered when Humanoid "dies" either because [[Health]] is 0 or because the Head and Torso are disconnected (Broken joints or one or both is removed).
The Died event is triggered when Humanoid "dies" either because [[Health]] is 0 or because the Head and Torso are disconnected (Broken joints or one or both is removed). You can prevent deaths through depleted health by keeping your health constantly above 0.


The event occurs after the automatic BreakJoints in model upon death, but before character falls and is removed.
The event occurs after the automatic BreakJoints in model upon death, but before character falls and is removed.


{{Example|<pre>
== Example ==
function onDied(character)
--do on death
end


function onCharacterAdded(character)
The code below would print <samp>A player has died.</samp> whenever a player dies.
character.Humanoid.Died:connect(function()
 
onDied(character)
{{code|=
game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
for _, child in next, character:GetChildren() do
if child:IsA('Humanoid') then
child.Died:connect(function()
print("A player has died.")
end)
end
end
end)
end)
end
end)
 
}}
function onPlayerAdded(player)
player.CharacterAdded:connect(onCharacterAdded)
end


game.Players.PlayerAdded:connect(onPlayerAdded)
[[Category:Events]]
</pre>}}

Latest revision as of 20:26, 9 April 2012

Died ( )
Description Fired after a Humanoid's health reaches 0.
Member of: Humanoid


Description

The Died event is triggered when Humanoid "dies" either because Health is 0 or because the Head and Torso are disconnected (Broken joints or one or both is removed). You can prevent deaths through depleted health by keeping your health constantly above 0.

The event occurs after the automatic BreakJoints in model upon death, but before character falls and is removed.

Example

The code below would print A player has died. whenever a player dies.

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		for _, child in next, character:GetChildren() do
			if child:IsA('Humanoid') then
				child.Died:connect(function()
					print("A player has died.")
				end)
			end
		end
	end)
end)