Help with a script

local name = game.Players.LocalPlayer.Name

script.Parent.SurfaceGui.TextLabel.Text = name

Theres something wrong with both lines. The first line got an error with no description and I put the second lines value to a string of random letters but it doesn’t work.

2 Likes

surface gui? so your running da script on workspace? with local script?

1 Like

What type of script is this? If it is a server script, LocalPlayer doesn’t work on it.

Try printing name and seeing if it works. Also, i’m not sure if this is intentional but the server won’t see the Text. You should use a remoteEvent.

no its a server script. Not a local.

That’s the issue. LocalPlayer is nil for the server.

doof. Alright. Well that stinks.

Okay. I will try that. Hope it works.

you can use PlayerAdded parameter to get the player in server script

This is LocalPlayer on the sever. It’s nil.
Player.LocalPlayer_Server
This is LocalPlayer on a client. It changes per client to their player instance in the Players Service. It’s a ObjectValue too.
Player.LocalPlayer_Client

Both Server and Client can access their character as long as you have the player, or you can get the character and use GetPlayerFromCharacter() to access the player.

you cant get " local player " from server script , do it in " starter player scripts " and with a " local script "