Cash label not loading

  1. What do you want to achieve? Keep it simple and clear!

I want a text label to display the amount of cash a player has. It should be visible at all times and also change its value if it detects a change.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that nothing shows up and the GUI is blank.

Screen Shot 2021-06-17 at 9.51.04 AM

Code

local cash = game.Players.LocalPlayer.leaderstats.Cash
local value = script.Parent


game.Players.PlayerAdded:Connect(function()
	game.Players.LocalPlayer.CharacterAdded:Connect(function()
		value.Text = "Cash: "..cash.Value

		while wait(1) do
			cash:GetPropertyChangedSignal('Value'):Connect(function()
				value.Text = "Cash: "..cash.Value
				wait(0.1)
			end)
		end
	end)
end)

The script is a local script inside the text label.

You don’t need a PlayerAdded, CharacterAdded, since it’s controlling a GUI, and you don’t need a While wait() because cash:GetPropertyChangedSignal will fire whenever the value changes.

local cash = game.Players.LocalPlayer.leaderstats.Cash
local value = script.Parent

value.Text = "Cash: ".. cash.Value

cash:GetPropertyChangedSignal('Value'):Connect(function()
	value.Text = "Cash: ".. cash.Value
end)
1 Like

You also don’t need to use GetPropertyChangedSignal, NumberValues and other value types have a special Changed function that only fires when Value is changed.

1 Like