Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Jxemes 75
7 years ago
Edited 7 years ago

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!

01local player = game.Players.LocalPlayer
02local statgui = player.PlayerGui:WaitForChild("StatGUI")
03local frame = statgui:WaitForChild("Frame")
04local coinframe = frame:WaitForChild("CoinFrame")
05local diamondframe = frame:WaitForChild("DiamondFrame")
06 
07local coins = coinframe:WaitForChild("Label")
08local diamonds = diamondframe:WaitForChild("Label")
09 
10function updateStatsToGUI()
11    local leaderstats = player:WaitForChild("leaderstats")
12    local coinsval = leaderstats:WaitForChild("Coins")
13    local diamondsval = leaderstats:WaitForChild("Diamonds")
14    coins.Text = ("     " ..coinsval.Value.. " Coins")
15    diamonds.Text = ("     " ..diamondsval.Value.. " Diamonds")
16end
17 
18 
19coins.Changed:connect(updateStatsToGUI)
20diamonds.Changed:connect(updateStatsToGUI)

1 answer

Log in to vote
1
Answered by 7 years ago

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:

01local player = game.Players.LocalPlayer
02local statgui = player.PlayerGui:WaitForChild("StatGUI")
03local frame = statgui:WaitForChild("Frame")
04local coinframe = frame:WaitForChild("CoinFrame")
05local diamondframe = frame:WaitForChild("DiamondFrame")
06 
07local coins = coinframe:WaitForChild("Label")
08local diamonds = diamondframe:WaitForChild("Label")
09 
10local leaderstats = player:WaitForChild("leaderstats")
11local coinsval = leaderstats:WaitForChild("Coins")
12local diamondsval = leaderstats:WaitForChild("Diamonds")
13 
14function updateStatsToGUI()
15 
View all 22 lines...
0
it doesn't work in Studio, but it works in Client. Which is still a good thing! Thank you! Jxemes 75 — 7y
0
Is this in a server script or a local script? konlon15 32 — 7y
Ad

Answer this question