How can I make a textlabel display the value of a leaderstat

ive been working on a 3d platformer and I have always wondered how people make those custom currency ui’s that save since I thought the only way to use datastores was with leaderstat

anyways is there a way to make text on a text label display the value of a leaderstat?

im not sure how to code but im guessing you would just check the value of the leaderstats and then change the Text property of the textlabel to display the value

Thanks

2 Likes

You pretty much have it there, put a local script inside of your text label and make a while loop that updates the text label’s text to the leaderstats value every second.

loop is bad, better do it with .Changed signal

leaderstatVal.Changed:Connect(function()  -- replace leaderstatVal with your value
    textlabel.Text = leaderstatVal.Value -- .Value if leaderstatVal is instance, without if variable
end)
3 Likes

sry i was away for a few days but ill try this now

Also make sure to have the same code outside the changed-function, to initialize the textbox text. Meaning it would be empty until leaderstatVal got updated otherwise.

leaderstatVal.Changed:Connect(function()  -- replace leaderstatVal with your value
    textlabel.Text = leaderstatVal.Value -- .Value if leaderstatVal is instance, without if variable
end)
textlabel.Text = leaderstatVal.Value -- .Value if leaderstatVal is instance, without if variable
1 Like

i got it working thanks tho

1 Like

its easy!

local plr = game.Players.LocalPlayer -- Assuming the script is local.
local leaderstats = plr:WaitForChild("leaderstats")
local money = leaderstats:WaitForChild("(money name here!)")
local textlabel = (display here!)
money:GetPropertyChangedSignal("Value"):Connect(function()
textlabel.Text = money.Value
end)
2 Likes

mark it as the solution if you get it working! i just posted code for no reason!

1 Like