Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I get character from player?

Asked by 4 years ago

Hi,

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

0
player.Character? laurenbtd5 379 — 4y
0
thank you! NoteSalad 17 — 4y

2 answers

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by
Shubu13 29
4 years ago
player.Character --;-;
0
sorry, very new to scripting, and couldn't find it in the object manager. NoteSalad 17 — 4y
0
oh ok Shubu13 29 — 4y

Answer this question