My GUI code for a button doesn't work!

Hello, everyone! I want my code to when a button is clicked change the Surface GUI’s text label (the text label is called “Username”.) to their username.



image

I have tried reviewing YouTube video’s but nothing is working!

Remove line 3 and 9, as both aren’t needed to make the script button work.

Change:

local Player = game.Players.PlayerAdded:Connect(function(Player)
end)

to:

local Player = game.Players.LocalPlayer

I think this is why your script doesn’t work. Also if you want to make the name visible to other clients use remote events. Here’s an example:

--Local Script
game.ReplicatedStorage.RemoteEvent:FireServer()
--Server Script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    Screen.Text = player.Name
end)

Under the SurfaceGui, you can see two children. They are both TextLabels. MouseButton1Click is only supported on TextButtons, ImageButtons etc, but aren’t supported on TextLabels. So, try changing the textlabels to textbuttons.