How would I check if a leaderstats value is changed?

Im trying to make a effect when the leaderstats value is changed but it does not seem like it works, this is what I have tried so far:

game.Players.LocalPlayer.leaderstats.Wood.Value.Changed:Connect(function()
	print("abvs")
end)

while true do
	if game.Players.LocalPlayer.leaderstats.Wood.Value.Changed then
		print("abvsss")
	end
	wait(0.001)
end

game.Players.LocalPlayer.leaderstats.Wood:GetPropertyChangedSignal("Value"):Connect(function()
	print("asdbas")
end)
1 Like
game.Players.LocalPlayer.leaderstats.Wood:GetPropertyChangedSignal("Value"):Connect(function()
	print("asdbas")
end)

Should work. If it doesn’t work for you, you should check the output. Also did you run these 3 methods in the same script? Because then this part wouldn’t even run since there’s a while loop above.

As smarties1920 said.

game.Players.LocalPlayer.leaderstats.Wood:GetPropertyChangedSignal("Value"):Connect(function()
	print("asdbas")
end)

The underlying reason why you script didn’t work is because of the while loop, if you where to add a thread where it wouldn’t make the rest of the script yield then that would fix it, which can be achieved by wrapping the while loop in a coroutine or thread via tasks, also events work for this as well since a event will create a new thread to call every function.

There’s no need to use GetPropertyChangedSignal for any ValueBase objects; the .Changed event only fires when the Value property changes, and passes the new value with it

1 Like