How to get Local Player's username

local Players = game:GetService("Players")
local LocalPlr = Players.LocalPlayer.Character.Name
local userId = Players:GetUserIdFromNameAsync(LocalPlr) -- later it will be"AamTum" (Local Player)

how do i make it work using local player/ self player char
ive tried using LocalPlayer.char but still, im using a script that’’ run on workspace
because i wanted to make a statue using it
where did i go wrong

Why?

local Players = game:GetService("Players")
local LocalPlr = Players.LocalPlayer.Character.Name
local userId = Players:GetUserIdFromNameAsync(LocalPlr) -- later it will be"AamTum" (Local Player)

Better:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local username = Player.Name
local userId = Player.UserId
1 Like

game.Players.LocalPlayer.Name

If you’re using a server script you won’t be able to get the local player’s name because there is no local player on the server. The local player refers directly to the player that’s controlling a client.

1 Like

What are you trying to do exactly? Load a specific player as a statue(lets say a dev)? Or load any player that joins as a statue?

load a localplayer’ self statue,
its more like a self statue, so every client see their own statue model, not only for a spesific player

@bioeless Was correct: The issues you’re experiencing are happening because you’re using a server Script instead of a LocalScript. LocalScripts don’t work inside of Workspace, and aren’t able to use LocalPlayer, so the easiest way to fix your problem would be to do this:

  1. Go to your script’s properties tab

  2. Change its RunContext to Client

This will make the server Script behave as a LocalScript, which will allow you to use LocalPlayer, and allow the script to run inside of Workspace

bioeless deserves the solution more than I do, since they managed to accurately guess the main problem before the screenshot was posted :slight_smile::+1:

1 Like