TextLabel to Stats Value

Hello, i’m ShyowwTheDev, you can call me Shyoww by short, and i will be showing you how to turn a TextLabel, into a stats value.

So first, you will need to add a ScreenGUI inside of StarterGUI, make sure your ScreenGUI properties have ResetOnSpawn off, then, inside of the ScreenGUI, add a TextLabel.
image
image

Second, you will add a LocalScript inside of the TextLabel (Leave the script alone for now).
image

Third, you will need to create a stats using leaderstats, if you don’t know how to, I recommend watching on YouTube or seeing tutorials on the DevForum itself. For example, i’ll be using a death stats:

game.Players.PlayerAdded:Connect(function(players)
 local leaderboard = Instance.new("BoolValue", players)
 leaderboard.Name = "leaderstats"
 local Deaths = Instance.new("IntValue", leaderboard)
 Deaths.Name = "Deaths" -- Make sure this is all together
 Deaths.Value = 0
 players.CharacterAdded:Connect(function(character)
  character:WaitForChild("Humanoid").Died:connect(function()
   Deaths.Value = Deaths.Value + 1
  end)
 end)
end)

And, now, for the final step, you should now edit the LocalScript inside of the TextLabel, here’s the script:

local deaths = script.Parent.Parent.Parent.Parent.leaderstats:WaitForChild("Deaths") -- Name of the IntValue or BoolValue.

function changed()
 script.Parent.Text = "deaths: " .. deaths.Value
end

deaths.Changed:Connect(changed)

And then, after all steps done, you should be good!


As you can see, the TextLabel gets the ammount of deaths i have from the leaderboard.

If you encounter any bugs, please tell me!
Peace! :v:

4 Likes

Probably the wrong category to put this in. Please refer to #resources:community-tutorials for easier access :slightly_smiling_face:

2 Likes

My bad, didn’t know that category existed. I’m still getting the hang of the DevForum.

2 Likes

You should also call changed immediately incase the client lags and this does not run right away! If the script runs after the deaths value has been set to something, it will not catch it.

1 Like

I didn’t quite understand this, i’m not that used to english so sorry.

local deaths = game.Players.LocalPlayer:WaitForChild("leaderstats").Deaths

local function changed()
    script.Parent.Text = "deaths: " .. deaths.Value
end

changed()
deaths.Changed:Connect(changed)
1 Like

Oh alright, that’s a bit better, thanks!

FORGOT TO MENTION

If your ScreenGUI properties is with ResetOnSpawn off, the text from the TextLabel will reset and won’t showcase the ammount of deaths (or anything) you have.
Remember to set your text to the text you want to be on the script.