How to show a stat value on a GUI?

I have a GUI and I want it to show the amount of Apps (name of my stat) , the player has:

So it would look something like

image

Does anyone know how to get this working?

I know that basic code but I can’t seem to compile it in my head.

6 Likes
local Player = game.Players.LocalPlayer
local TextLabel = script.Parent.TextLabel

while true do
TextLabel.Text = Player.leaderstats.Apps.Value
end

Change the text to the value

1 Like

@SpacialEthanRB Woah there, don’t put a while loop without a wait buddy, that would cause the game to crash.


My approach to this would be setting the text at the top of the script then hook up the .Changed function of the Apps value.

local Player = game.Players.LocalPlayer
local leaderstats = Player:WaitForChild("leaderstats")
local Apps = leaderstats:WaitForChild("Apps")
local TextLabel = script.Parent.TextLabel

TextLabel.Text = Apps.Value

Apps.Changed:Connect(function(newValue)
    TextLabel.Text = newValue
end)
5 Likes

This worked!
Thanks!

commits 30 characters

2 Likes

well the “newValue” would cause an error
you should change it to

Apps.Changed:Connect(function()
    TextLabel.Text = Apps.Value
end)

Why are you bumping a topic 2 years later?

newValue would work as the new value is passed into the first parameter of the function connected to IntValue.Changed.

1 Like

I tested it earlier and it didnt work…
why do i keep saying things late, i have a mental problem or something