Having a specific players’ leaderstats value appear in a GUI

Hey Guys! I would like to make a user interface that shows a specific players’ leaderstat value

  1. What do you want to achieve? I would like to achieve a user interface that displays a certain users’ leaderstat value in a playerlist. I am currently using Shiroo’s custom playerlist so that’s where you can find the player’s username for defining the value. All I need is a base of a script not an entire script.
  1. What is the issue? I don’t know how to script.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes I did but it did not cover what I was looking for.

So insert a script into a textlabel. Say you have a layout like this:

GUI - Frame - TextLabel - Script

If so put this script:

local player = script.Parent.Parent.Parent.Parent.Parent -- amount of parents the children have.

local leaderstats = player:WaitForChild("leaderstats")
local stat = leaderstats:WaitForChild("StatName") -- change StatName to your stat's name

script.Parent.Text = stat.Value

stat.Changed:Connect(function()
script.Parent.Text = stat.Value -- say you wanted the text to be StatName: StatValue. If so put "StatName"..stat.Value and change StatName to whatever you want it to write.
end)
4 Likes

Thanks for helping. I am absolute crap at scripting.

1 Like

For the player, could I just go to
local player = game.StarterPlayer or something?

1 Like

Or is it to the other TextLabel with the player’s name?

1 Like

game.Players.LocalPlayer only works on the client side.

1 Like

How would I make it not be of the local player, but on a custom leaderboard so that it shows stats globally?

Edit: leaderboard/playerlist

1 Like

Basically when the game loads in, all the players get the guis from StarterGui and they get put into the player’s playergui. The localized player is the actual player object.

1 Like

You would put a script into the leaderboard gui.

Put this in it:

for i,plr in pairs(game.Players:GetChildren())do
if plr then
local pgui = plr.PlayerGui
local leaderboard = pgui:WaitForChild("LeaderboardGui") -- name of leaderboard gui
 local player = script.Parent.Parent.Parent.Parent.Parent -- amount of parents the children have.

local leaderstats = plr:WaitForChild("leaderstats")
local stat = leaderstats:WaitForChild("StatName") -- change StatName to your stat's name

script.Parent.Text = stat.Value

stat.Changed:Connect(function()
script.Parent.Text = stat.Value -- say you wanted the text to be StatName: StatValue. If so put "StatName"..stat.Value and change StatName to whatever you want it to write.
end)
end
2 Likes

so the final script would be a mix of the two? im very confused.

Yes, that would be the case. 30 chars.

What changes would need to be made?

1 Like

I just changed it. You will need to tweak with the parent parts to work with the children and parents of your leaderboard gui.

2 Likes