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