Get Player **object** from Player username

I know there’s a function that allow’s you to get a players character based of there username.

Example

local Player = Players:GetPlayer('HeWo30')
Player.Character -- // etc etc etc...

But I can’t find it anywhere.

To get the character, you can simply do:

local Players = game:GetService("Players")
local Player = Players:FindFirstChild("Username")

if (Player ~= nil) then
    local Character = Player.Character 
end

This will only work if the player is in the game though

1 Like

GetPlayerFromCharacter() or game:GetService(“Players”):FindFirstChild(Username)

1 Like

???
GetPlayerFromCharacter()
This require’s the character.

Yeah I know, I messed up. but is the second suggestion the one you’re looking for?

1 Like

I was planning on having something like

-- // Get player object from username
local Player = functionHere('Username')
Player.UserId
Player.Name
Player.DisplayName
function FunctionHere(Name): Player?
   if Players:FindFirstChild(Name) then
      return Players:FindFirstChild(Name) -- will return player object.
   end
end

Like this?

1 Like

This is highly redundant when you can just do local player = Players:FindFirstChild(username)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.