When I try to see when the value of a leaderstat changes it returnes a error

When I try to see when the value of a leaderstat changes it returnes this error

Players.MasonX890.PlayerScripts.UI.Main:12: attempt to index number with 'Changed'

wait()
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local CashAmountUI = PlayerGui.MainUI.LeftMain.Cash.Container.Container.CashAmount

– Cash Gui
CashAmountUI.Text = “$”…Player.leaderstats.Cash.Value
Player.leaderstats.Cash.Value.Changed:Connect(function(New)
CashAmountUI.Text = “$”…New
end)
– Level Gui
PlayerGui.MainUI.LeftMain.XP.Container.Icon.RankLabel.Text = Player.leaderstats.Rank.Value
Player.leaderstats.Rank.Value.Changed:Connect(function(New)
PlayerGui.MainUI.LeftMain.XP.Container.Icon.RankLabel.Text = New
end)

My script:

wait()
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local CashAmountUI = PlayerGui.MainUI.LeftMain.Cash.Container.Container.CashAmount





-- Cash Gui
CashAmountUI.Text = "$"..Player.leaderstats.Cash.Value
Player.leaderstats.Cash.Value.Changed:Connect(function(New)
	CashAmountUI.Text = "$"..New
end)
-- Level Gui
PlayerGui.MainUI.LeftMain.XP.Container.Icon.RankLabel.Text = Player.leaderstats.Rank.Value
Player.leaderstats.Rank.Value.Changed:Connect(function(New)
	PlayerGui.MainUI.LeftMain.XP.Container.Icon.RankLabel.Text = New
end)

Remove the .Value here and

here

You’re using .Cash.Value.Changed, however you should be using .Cash.Changed, however scrapping that, it might be better to use :GetPropertyChangedSignal instead. Not sure the implications of using Changed on something like a NumberValue which really only has one main property anyways, however I’d recommend it anyways just to make sure you’re precisely only changing stuff when the value itself changes.

Player.leaderstats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
-- code here
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.