Trying to change SurfaceGui's Text but not working

I’ve seen other problems like mine and tried using their solutions but it still isn’t working.
It’s in a LocalScript because Scripts were not working.
Here’s my code

local Name = game.Players.LocalPlayer.Name
local Player = game:GetService("Players").LocalPlayer
local Players = game:GetService("Players")
local HouseSign = game.Workspace.HouseSign
local surfaceGui = HouseSign.SurfaceGui 
local textLabel = surfaceGui.TextLabel

textLabel.Text = Name.."house"

If I’m not mistaking it has to be in a script, however you won’t be able to use LocalPlayer on the server. Thats why your Regular scripts are not working

1 Like

Try putting the local script in StarterPlayerScripts which is located in StarterPlayer

1 Like

Try this code:

local PS = game:GetService("Players")

local Player = PS.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Name = Char.Name

local HouseSign = workspace.HouseSign
local surfaceGui = HouseSign:FindFirstChild("SurfaceGui")
local textLabel = surfaceGui:FindFirstChild("TextLabel")

if surfaceGui and textLabel then
    textLabel.Text = Name.."house"
else
    warn("SURFACE GUI AND TEXT LABEL ARE NIL")
end

1 Like

Like what @domboss37 said:

You cannot use LocalPlayer on a server script because it can be only accessible to the client.

If you were planning to change it via the server, you could probably do something with PS:GetPlayers() and a generic loop (for i,v in pairs).

the poster said it is already in a local script, they probably did not include LocalPlayer on the server script

Well in that case, he should try this:

My guess to it not working is because something in his code is nil. Maybe surfaceGui doesn’t exist? Or even the character’s name?

Oh wait, there’s already a solution.

if it was on a Server script, he shouldve put it in ServerScriptService, but in this case it is a LocalScript which means he should include it in StarterPlayerScripts located in StarterPlayer

1 Like