Hi all! Today I will be showing you how to load a player’s leaderstats in a GUI!
(Note: Please ignore the other things you might see in the explorer as am working on a game but just came up with the idea to make this tutorial to help others)
What we are making!
Step 2
Add a script
inside ServerScriptService
and write in it this code:
game.Players.PlayerAdded:Connect(function(player)
print("player found")
local leaderstats = player:WaitForChild("leaderstats")
print("leaderstats found")
local cash = leaderstats:WaitForChild("Cash")
print("cash found")
local cashscreengui = player.PlayerGui:WaitForChild("Cash")
local cashgui = cashscreengui:WaitForChild("TextLabel")
print("Cash GUI found")
cashgui.Text = cash.Value
cash.Changed:Connect(function()
cashgui.Text = cash.Value
end)
end)
Code explanation
The 1st line gets the player.
Lines 2 - 7 get the stats etc. (all the prints are to verify the script is working at each step)
The line cashgui.Text = cash.Value sets the value
Lines 8 - 10 “update” the GUI if the player’s leaderstats change.
And done!
Extra Details
- Make sure your explorer matches to the screenshot in Step 1 (please ignore the other 2 GUIS)
- Make sure all scripts are enabled.
- Make sure to change the names to your GUIs if your having different names.
- If it’s still not working please contact me on the devforum or on discord anirudh851#3224. Messaging on the devforum is recommended as I don’t see discord quite often.
- If you can’t make it then here is the CashScript: CashScript.rbxm (812 Bytes)
Put the script in ServerScriptService
Here is the GUI: CashGUI.rbxm (2.5 KB)
Put the GUI in StarterGui
Thanks for reading and hope this helps! Feel free to give feedback below!