Is there any way to get the player character from the player?

I want to know if there is any way to get a player character in the workspace, if you only have the character from game.Players. Here’s what I mean.

So if you want to get the player from character, you would do game.Players.GetPlayerFromCharacter(). My question is, is there a way to do it the other way around? like game.Players.GetCharacterFromPlayer()

I’m not sure if this makes sense, but if it does, let me know how I could do this.

It’s a property with player, simply player.Character , often paired with player.CharacterAdded:Wait() to ensure the character is added and spawned first.

player.Character refers to the character model IF it’s loaded, you’d be referencing that!

local character = workspace:FindFirstChild(player.Character.Name) or nil
local char = player.Character or player.CharacterAdded:Wait()

I know of that. I forgot to mention that I’m doing a script on a player being added:

game.Players.PlayerAdded:Connect(function(player)
      --[[
         In here I'm trying to get the character from the player arguement that 
I set, because right now my "player" arguement is referenced to
game.Players.Gvvgghnu_Lol. I want to reference it to game.Workspace.Gvvgghnu_Lol
      --]]


end)
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait() -- game.Workspace.PlayerName
-- stuff here
end)

or if you want the event to fire everytime the player character gets added

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
-- Stuff here
end)
end)

I also forgot to mention that I’m trying to set the player character to anchored so they can’t move…I won’t go on with why I’m trying to do that but that’s basically my ultimate goal.

you can anchor the player’s HRP

thats what I’m trying to do, the thing is I can’t get the players character from workspace to be able to anchor it in the first place. I’ll try your code and see if it works.

char will be the player’s character aka game.Workspace.PlayerName

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.HumanoidRootPart.Anchored = true
end)
end)

thanks bro. I don’t normally deal with this kinda stuff so I was confused with how I can reference things.

1 Like