Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Text Label not Updating?

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

✓ Accepted answer

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!

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.