Cash count on GUI

Hi guys,I made a simple cash indicator on the leaderboard,but for some reason it messed up with the score indicator (always on the leaderboard).How can I connect the cash script to a custom GUI without showing it on the leaderboard?
This is the cash script

– code
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local cash = Instance.new("NumberValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = 50 -- 50 starting cash
end)
3 Likes

You can use the .Changed event on the UI to check when the cash value is edited to update the UI. It would look something like this:

--- Local script in UI
local plr = game.Players.LocalPlayer
local GUI = script.Parent
plr.leaderstats.Cash.Value.Changed:Connect(function()
GUI.Text.Value = tostring(plr.leaderstats.Cash.Value)
end)
3 Likes

Well to not show it on the leaderboard, you shouldn’t have a folder called “leaderstats.” the only reason you’d have that is because you want to show it publicly on the leaderboard. And then yeah, the GUI can automatically update via. a localscript whenever the cash value is changed using topdog_alpha’s script above.

2 Likes

To not show it on the leaderboard, simply parents it to the player, don’t parent it to a leaderstats named folder.

And you should access The playerGui not StarterGui. Most beginners fail for this.

2 Likes

Aye that’s true. Misread that.
He should still parent it to the player however as this would prevent exploiters editing how much cash they have as they can access it if it is on the client and he would still want to use the .Changed event to update the UI whenever the value Cash is changed

1 Like

Addition: .Changed is a good way but still, :GetPropertyChangedSignal("Value") is better

2 Likes

So I have to delete this strings for hide it from the leaderboard?

– code
local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"

and then remove “leaderstats” from

– code
local cash = Instance.new("NumberValue",leaderstats)
1 Like

you can just parent it to the player like:

local cash = Instance.new("IntValue", player)
2 Likes

Whilst that is also a good way to do it, that doesn’t work with a NumberValue and should be used with an IntValue

1 Like

As @Thanhpro291368 said you do not need a folder called leaderstats if you do not want it displayed on the leaderboard. All you need to do is just parent the value Cash directly to the player or create a different folder inside the player to put your values inside that isn’t called leaderstats.

3 Likes

So I have to write something like

– code

local leaderstats = Instance.new("Folder",player)
local cash = Instance.new("IntValue", player)
	cash.Name = "Cash"
	cash.Value = 50 -- 50 starting cash
end)

Yes, just like that. Now cash will be parented to the player rather than the leaderstats.
Anything you now parent to the folder leaderstats will be visible on the leaderboard. Anything parented to the player will not be visible on the leaderboard

Thank you very much,so then I have to create a GUI with that local script that you mentioned before?But I have only one question.The cash is not shown on the leaderboard,before when you gave me that local script,there were these strings

– code
plr.leaderstats.Cash.Value.Changed:Connect(function()
GUI.Text.Value = tostring(plr.leaderstats.Cash.Value)

These two lines of code mentioned the “leaderstats”.But if the the cash is not parented anymore with the leaderstats ,what I have to do with these two lines of code?

Remove the leaderstats from the script?
(30 chars)

Just replace the plr.leaderstats.Cash with the pathway to the cash value.
If you are now putting the cash value in player all you will need to do is remove leaderstats from the lines

For values, Changed is better cause values use a different Changed event, which only fires when the Value property changes

So in the local script inside of the GUI I just have to edit that line as “prl.Cash”

Put the local script inside the GUI which displays cash and change the value GUI in the script to the textbox that is displaying the cash

2 Likes

This is valid with any type of GUIs or I have to use a text label?

Well you can only display text via a textlabel

1 Like