Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a GUI that shows the stats in your leaderstats?

I'm currently making a GUI Frame that has two things: A TextLabel for Coins, and a TextLabel for Diamonds. I'm adding function to make it update whenever the Coins/Diamonds stat changes in player's leaderstats.

This script and GUI is also not for making a leaderboard and replacing the ROBLOX's default one, but it could be a leaderboard that replaces ROBLOX's default one.

I scripted it, but the problem is, it's not working, and it doesn't show any wrong errors.

If you guys know what's happening that is wrong, or have any tips, tell me please!

local player = game.Players.LocalPlayer
local statgui = player.PlayerGui:WaitForChild("StatGUI")
local frame = statgui:WaitForChild("Frame")
local coinframe = frame:WaitForChild("CoinFrame")
local diamondframe = frame:WaitForChild("DiamondFrame")

local coins = coinframe:WaitForChild("Label")
local diamonds = diamondframe:WaitForChild("Label")

function updateStatsToGUI()
	local leaderstats = player:WaitForChild("leaderstats")
	local coinsval = leaderstats:WaitForChild("Coins")
	local diamondsval = leaderstats:WaitForChild("Diamonds")
	coins.Text = ("     " ..coinsval.Value.. " Coins")
	diamonds.Text = ("     " ..diamondsval.Value.. " Diamonds")
end


coins.Changed:connect(updateStatsToGUI)
diamonds.Changed:connect(updateStatsToGUI)

1 answer

✓ Accepted answer

It's quite simple really. You're calling the updateStatsToGUI() function when the coins gui object updates. What you want to do is call it when the coinsval object updates, since this is the value.

This script should work:

local player = game.Players.LocalPlayer
local statgui = player.PlayerGui:WaitForChild("StatGUI")
local frame = statgui:WaitForChild("Frame")
local coinframe = frame:WaitForChild("CoinFrame")
local diamondframe = frame:WaitForChild("DiamondFrame")
 
local coins = coinframe:WaitForChild("Label")
local diamonds = diamondframe:WaitForChild("Label")
 
local leaderstats = player:WaitForChild("leaderstats")
local coinsval = leaderstats:WaitForChild("Coins")
local diamondsval = leaderstats:WaitForChild("Diamonds")

function updateStatsToGUI()

    coins.Text = ("     " ..coinsval.Value.. " Coins")
    diamonds.Text = ("     " ..diamondsval.Value.. " Diamonds")
end

 
coinsval.Changed:connect(updateStatsToGUI)
diamondsval.Changed:connect(updateStatsToGUI)

2 comments

0

it doesn't work in Studio, but it works in Client. Which is still a good thing! Thank you!

0

Is this in a server script or a local script?

This discussion is preserved as it was. New answers, comments, and votes are closed.