Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do u get character from player?

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

2 answers

✓ Accepted answer
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.

3 comments

0

I got an error while trying this. Character is not a valid member of workspace.

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?

0

^ oh, you're right i truly messed up there

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.

1 comment

0

The error explains itself. You're doing the function on the Workspace instead of the player.

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