Hi,
I was wondering how I got the character of a player, it's like the "GetPlayerFromCharacter()" but reversed.
Hi,
I was wondering how I got the character of a player, it's like the "GetPlayerFromCharacter()" but reversed.
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 --;-;
sorry, very new to scripting, and couldn't find it in the object manager.
oh ok
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
player.Character?
thank you!