Update Text from leaderstat value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a text label that shows how much clicks you have.
  2. What is the issue? Include screenshots / videos if possible!
    When I run the script, the text still stays at zero instead of an updated number.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Trying on here.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local text=script.Parent
local plr=game.Players.LocalPlayer
local click=plr.leaderstats.Clicks
local clickVal=plr.leaderstats.Clicks.Value
text.Text="Clicks:"..clickVal
print("evenbetterhi")
while wait() do
	print("hi")
	text.Text="Clicks:"..clickVal
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

local clickVal=plr.leaderstats.Clicks.Value

Defining this will make it static. clickVal will always be the value it was by default.
Instead, do this:

click.Changed:Connect(function (Value) --to prevent unnecessary loop
   text.Text = click.Value
end)
1 Like

Even better, use GetPropertyChangedSignal() to detect changes to the specific property only:

local players = game:GetService("Players")
local client = players.LocalPlayer

local leaderstats = client:WaitForChild("leaderstats")
local clicks = leaderstats:WaitForChild("Clicks")

clicks:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = `Clicks: {clicks.Value}`
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.