Character (Property): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>LPGhatguy
Added "clear floats" to keep everything in-line
>JulienDethurens
No edit summary
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{CatUp|Properties}}
{{redirect|Character|My Character|user characters}}


<onlyinclude>
<onlyinclude>{{Property
{{Property|
|name = Character
name = Character
|type = {{type|instance=Model}}
|property = [[Instance|Model]] ''Character''
|description = A model containing the parts, joints, and scripts for the corresponding Character to the Player in Workspace.
|description = A model containing the parts, joints, and scripts for character.
|object = Player
|object = [[RBX.lua.Player (Object)|Player]]
}}</onlyinclude>
|}}
</onlyinclude>


{{clear floats}}
{{clear floats}}
Line 15: Line 13:
The Character property is initially nil. But is set when the Character is spawned.
The Character property is initially nil. But is set when the Character is spawned.


== Example ==


This code demonstrates the use of the Character property. First, we print the character while it hasn't loaded yet, which should print <samp>nil</samp>. Then, we print it after making sure it has loaded, which should print its name.


Example:
{{code|=
<pre>
game.Players.PlayerAdded:connect(function(player)
function onPlayerAdded( player )
print(player.Character)
print( player.Character ) -- nil
player.CharacterAdded:wait()
player.CharacterAdded:wait()
print(player.Character)
print( player.Character ) -- set (.Name==player.Name)
end)
end
}}
Game.Players.PlayerAdded:connect( onPlayerAdded )
</pre>


== See Also ==
To get a player from a character, you can use a 'for' loop, but it is preferable to use the [[GetPlayerFromCharacter (Method)|:GetPlayerFromCharacter() method]].
[[CharacterAdded (Event)|CharacterAdded]]
 
[[PlayerAdded (Event)|PlayerAdded]]
== See also ==
*[[CharacterAdded]]
*[[PlayerAdded]]


[[Category:Properties]]
[[Category:Properties]]

Latest revision as of 22:22, 2 May 2012

"Character" redirects here. For user characters, see My Character.
Character
Type Model
Description A model containing the parts, joints, and scripts for the corresponding Character to the Player in Workspace.
Member of Player


Description

The Character property is initially nil. But is set when the Character is spawned.

Example

This code demonstrates the use of the Character property. First, we print the character while it hasn't loaded yet, which should print nil. Then, we print it after making sure it has loaded, which should print its name.

game.Players.PlayerAdded:connect(function(player)
	print(player.Character)
	player.CharacterAdded:wait()
	print(player.Character)
end)

To get a player from a character, you can use a 'for' loop, but it is preferable to use the :GetPlayerFromCharacter() method.

See also