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

How do u get character from player?

Asked by 6 years ago

There is a function called GetPlayerFromCharacter(), but i want to do the opposite.

2 answers

Log in to vote
1
Answered by 6 years ago
function GetCharacterFromPlayer(player)
if player.Character then
return player.Character
end
end
--This function just returns the character if there is one.

You can also do player.Character, but it's better if you check if it isn't nil.

Short answer: You can use the Character property to access the character.

0
I got an error while trying this. Character is not a valid member of workspace. kattenverzorger 23 — 6y
1
Whats the point in checking if the character exists in your function since it returns nil if it doesn't exist, like how "player.Character" has when there is no character? hiimgoodpack 2009 — 6y
0
^ oh, you're right i truly messed up there brokenVectors 525 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
newpart.Position = GetCharacterFromPlayer(script.Parent.Parent.Parent).Head.Position

If i do this, i get an error: Character is not a valid member of Workspace.

0
The error explains itself. You're doing the function on the Workspace instead of the player. brokenVectors 525 — 6y

Answer this question