OnScreen Cash gui not working

trying to make a on screen cash gui n is isnt working.
Script:

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

Screenshot 2021-12-21 184939

This is because you’re not letting it update, your code is only checking the leaderstats one time.

Example you can use:


local Coins = game.Players.LocalPlayer.Coins

CoinsLabel.Text = tostring(Coins.Value)
Coins:GetPropertyChangedSignal("Value"):Connect(function()

	CoinsLabel.Text = tostring(Coins.Value)

end)

this code will find out if their were updates to the certain value you’re wanting to display, sadly this won’t abbreviate your numbers.

Tried it in Local script n normal script n its still not working

I assume leaderstats or Cash takes a while to load breaking the script with an “attempt to index nil” error on the first iteration, if that’s true you can handle it by using WaitForChild for example:

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
--we wait for each element to load
local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")

script.Parent.Text = ": "..Cash.Value
--instead of looping, we can listen for value changes
Cash.Changed:Connect(function()
	script.Parent.Text = ": "..Cash.Value
end)
1 Like

works thank you so much have a good day/night

1 Like