Died (Event): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
initial from memory
>JulienDethurens
No edit summary
 
(28 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{CatUp|Events}}
<onlyinclude>{{Event
{|
|name = Died
|<onlyinclude>{{Event|name=Died
|description = Fired after a Humanoid's health reaches 0.
|arguments=
|object = Humanoid
|description= Fired after a Humanoid dies.
}}</onlyinclude>
|object= [[RBX.lua.Humanoid (Object)|Humanoid]]
 
|}}
{{clear floats}}
</onlyinclude>
 
|}
== Description ==
== Description ==
Died event is triggered when Humanoid "dies" either because [[Health (Property)|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.
Line 15: Line 14:
== Example ==
== Example ==


<pre>
The code below would print <samp>A player has died.</samp> whenever a player dies.
function onDied(character)
-- do on death
end
 
function onCharacterAdded(character)
character.Humanoid.Died:connect( function() onDied( character ) end )
end
 
function onPlayerAdded(player)
player.CharacterAdded:connect( onCharacterAdded )
end


game.Players.PlayerAdded:connect(onPlayerAdded)
{{code|=
</pre>
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)
}}


[[Category:Events]]
[[Category:Events]]

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)