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!

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

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:

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)
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