Why is my GUI not showing the amount of cash?

Hi, i have a CashGui, but when i have cash i doesn’t show right amount, it just shows 0

This is the part of leadboard (cash part):

local currency = Instance.new("IntValue",folder)
	currency.Name = "Cash" 
	currency.Value = 0 

And this is the GuiScript:


local Cash = script.Parent.Parent.Parent.Parent.leaderstats.Cash
Cash.Changed:Connect(function() 
	script.Parent.Text = "Cash: $"..Cash.Value
end)

i also tried

--local Cash = game.Workspace.leaderstats.Cash

local Cash = game:GetService("ServerScriptService").Leaderboard.Cash

Cash.Changed:Connect(function()

script.Parent.Text = "Cash: $"..Cash.Value

end)

Also tried this one

local Cash = game.ServerScriptService.leaderstats.Cash 
Cash.Changed:Connect(function() 
	script.Parent.Text = "Cash: $"..Cash.Value
end)

None of those works :sad:
Please help me fix it. Thank you :slight_smile:

Try putting the GUI script inside StarterPlayerScripts and update the Cash Variable.

IGNORE THIS PART
I misread the original scripts.
You are relying on Values, but the Value objects have properties named Value, to return the actual amount within the value.
So instead of

game.Workspace.Cash

use
game.Workspace.leaderstats.Cash.Value
READ THIS PART!!!
And yes, as Disc said, you have to make sure this is from a local script, but the GUI values should never be updates based off of the amounts in the workspace, as someone can easily change their local leaderstats to show something different. You can rely on it just for the GUI, but do not rely on Values stored on the client in order to change the actual data stores or check for amount of money when making a purchase.

Important
you will have to use Remotes in order to update the Gui Locally. Or, rather, it is better practice to do so. You can’t change the server values from the client, and while you CAN change the client values from the server, it’s best to connect it with a remote.

4 Likes

image With the TextLabel or just the script? :thinking:

Just the script.

30 charssssss

Make sure you update the variables

try using this:

while wait() do
script.Parent.Text = "$"..game.Players.LocalPlayer.leaderstats.Cash.Value
end

you can adjust the text to how you like.

2 Likes

Nope, still didn’t work :confused:
30 chars

Stick with the event-based method.

Instead of referencing the player through a mess of “.Parent” just use the local player.

local Cash = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash
Cash.Changed:Connect(function() 
	script.Parent.Text = "Cash: $"..Cash.Value
end)

Tried yours but still:

Nope, still…

With mine you need to reset, i forgot to put WaitForChild.

Do any errors get printed? Like “Attempt to index nil with …” or anything else?

2 Likes

Tried to reset but still…

Hey your primary issue here is you are attempting to get a value stored in ServerScriptService, from a localscript inside of a gui object. This is something you cannot do. The solution is to use a RemoteEvent to change the player Cash in their local GUI.

That isn’t true, his script in serverscriptservice makes a folder inside of the player, so in this case it can be accessed by going through the player.

Only error i found associated with the leaderstats
image

If he’s using the standard playerlist leaderboard system then each player should have a folder named “leaderstats” containing an IntValue named “Cash”

ohhhh, turn on api access in your game settings.

3 Likes

Yes… There was never any mention of errors.If the script is never able to update the leaderstats… then the Changed never fires.