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

How to Get a Character From a Player()?

Hello guys so I am sure a lot of you know the way GetPlayerFromCharacter() works its when you usually use an event that triggers the player's body in workspace and gets their player form in the players category I want to do the opposite I want to get the character from player and I don't really know how to do that here is my script so far

game.Players.PlayerAdded:Connect(function(player)
	local bob = player:GetCharacterFromPlayer()
	
	local it = Instance.new("Part",bob.HumanoidRootPart)
end)

1 comment

0

player.Character is the character you want

3 answers

✓ Accepted answer

Get the character like this:

local char = workspace:FindFirstChild(player.Name)

Hope this helped.

6 comments

0

This can lead to erros, lets say that a player called "Part" joins, it may select any part called "Part" on his workspace

0

mmmm that would be true but the thing is that is impossible right as a roblox user needs to be a certain length?

0

I looked it up and there is indeed a person named part but that user hasn't been online since 2 years soooo

0

You could use tostring and prevent that from happening.

0

You could use tostring and prevent that from happening.

0

You could use tostring and prevent that from happening.

In the future please add punctuation so we can understand faster and diagnose the problem with more accuracy.

Anyway here you go, its player.Character

Here is how it works.

game.Players.PlayerAdded:Connect(function(player)
    local bob = player.Character

    local it = Instance.new("Part",bob.HumanoidRootPart)
end)

Its simply an attribute that links directly to the Character.

1 comment

0

ah thank you I didn't see this I should have accepted your answer as it is much clearer

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