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 get character from player?

Hi,

I was wondering how I got the character of a player, it's like the "GetPlayerFromCharacter()" but reversed.

2 comments

0

player.Character?

0

thank you!

2 answers

✓ Accepted answer

You can access the Character through player.Character. As a general rule of thumb, you always want to take into consideration the fact that the character may very well be nil. If this were true, it would throw an error. Hence, we can use wait for the CharacterAdded event to fire to fix this potential problem.

From the Client:

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

From the server:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		print(char.Name) 
	end)
end)
player.Character --;-;

2 comments

0

sorry, very new to scripting, and couldn't find it in the object manager.

0

oh ok

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