How to load a player's leaderstats into a GUI

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 1

Make a gui and add a textlabel in it:

Step 2

Add a script inside ServerScriptService and write in it this code:

	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
		cashgui.Text = cash.Value
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

  1. Make sure your explorer matches to the screenshot in Step 1 (please ignore the other 2 GUIS)
  2. Make sure all scripts are enabled.
  3. Make sure to change the names to your GUIs if your having different names.
  4. 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.
  5. 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!


Upload place file next time for peoples cant make it, Nice tutorial

1 Like

I might be missing something, but how does this line work?

Don’t you need to change the PlayerGui, not the StarterGui? Also the player added function will mean that everyone’s gui will change whenever someone else’s cash changes.

1 Like

Yea, that would be an uh oh. Everyone will see their cash changing left and right to someone else’s.

It also took me a second to realize that the ScreenGuis name was “Cash”.


Please change this to say “Add a LocalScript”
You also don’t need the onplayeradded in a local script. Just do something like:

local player = game:GetService("Players").LocalPlayer
local leaderstats = player:WaitForChild("leaderstats",20)
local cash = leaderstats:WaitForChild("Cash",20)
local cashGui = script.Parent
cashGui.Text = cash.Value
	cashGui.Text = cash.Value
1 Like

Fixed it! I missed the word local :sweat_smile:

Oopsy. Looks like a I missed typed a thing or two. Sorry :sweat_smile:

Yup! Didn’t realize it at that time :sweat_smile:Changed it!

Will upload it soon! Thanks for your feedback!

1 Like

Hi again! Instead of changing it to a localscript I kept it in a script and it works now. Tested with my both accounts together and it showed different for both of them.

Great job. Thanks for posting this tutorial, it will be helpful for some people on the forums

1 Like

Uploaded the place files as well. Thank you.

1 Like