Today, I have been trying to figure out if should use player.character or workspace:waitforchild(player.name). they both work the same, but is there a difference?
Which do you use?
- Player.Character
- workspace:WaitForChild(player.Name)
0 voters
Today, I have been trying to figure out if should use player.character or workspace:waitforchild(player.name). they both work the same, but is there a difference?
Which do you use?
0 voters
local Character = Player.Character or Player.CharacterAdded:Wait()
The former. Always. Player.Character
is guaranteed to point to the character, only exception is it will be nil
if the character hasn’t loaded yet. But that is where the method demonstrated by @kylerzong comes in. Grabbing the character from the workspace is bad practice, it grabs anything with the name of the player, so it doesn’t have to necessarily be the character.
Yea, I realize that when testing, it can grab anything that has that player.name. but I’m still wondering if people use it.
Anyone that does doesn’t know better, there is literally no reason to grab the character through an unofficial method when an official one exists lol
If you have, for example, a Dummy or a Clone (maybe from a :clone admin command) then workspace:WaitForChild(player.Name)
would possibly refer to that Dummy or Clone.
Using workspace:WaitForChild(player.name) can be really bad as players may sometimes be named the same as an object/model in workspace.
Thinking about you could check if the player has Humanoid and some kinda folder or value that would work but that would be a bad idea.
if game.Players:GetPlayerFromCharacter(SupposedPlayerCharacter) ~= nil then
-- stuff
end