Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Text Label not Updating?

Asked by
bdam3000 125
4 years ago

I'm trying to make a button that gives you clicks when you click it. I have a Text Label to show how many clicks I have

This is a LocalScript:

local button = script.Parent -- Button that is clicked

button.MouseButton1Click:Connect(function()
    local number = game.StarterGui.ScreenGui.Number -- textlabel (the text is a number)
    local value = game.Players.LocalPlayer.Clicks.Clicks -- intvalue
    value.Value = value.Value + 1

    number.Text = (value.Value)




end)

The Scripts works, but the text label won't update when the name changes. This is probably because im doing this with a text label or that im changing the name instead of making a leaderstat, but if you have any answers please help.

1 answer

Log in to vote
0
Answered by 4 years ago

The problem is that when you game initializes, the contents of StarterGui go to the PlayerGui, wich in the explorer is under game.Players.UserName.PlayerGui. Since you're on a local script, you can access the player using game.Players.LocalPlayer. Here is your script fixed:

local button = script.Parent -- Button that is clicked
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()

    local number = player.PlayerGui.ScreenGui.Number -- textlabel (the text is a number)
    local value = player.Clicks.Clicks -- since i defined player above then we can make this line shorter

    value.Value = value.Value + 1

    number.Text = (value.Value)

end)

Hope this fixed your problem!

0
Thanks! bdam3000 125 — 4y
Ad

Answer this question