How can I make it so the when the player gets +1 leaderstat, the sound plays?

I tried doing it without the loop, but then it only did it once, I’m not sure why. So I tried the while true do, but now it will constantly play, any help is greatly appreciated!

while true do
if player.leaderstats.Stage.Value + 1 then
	task.wait(0.4)
	stagecounter.Parent.Sound:Play()
end
end

You could bind a .Changed event to Stage and checking if the new value is greater than the old value:

player.leaderstats.Stage.Value.Changed:Connect(function(oldValue, newValue)
    if newValue > oldValue then
        stagecounter.Parent.Sound:Play()
    end
end)

Let me know if this doesn’t work, on my phone so can’t test it.

Didn’t work, the output says something with when it said Changed.

isnt it getpropertychangedsignal?

I saw that connecting a value to .Changed only passes through the new number that changed… Not an old and new value… ;-;

You can still use .Changed, but you’d need to keep track of the previous value somewhere, this is bad practice but this would be the example with the previous value being stored as a global in the script.

local previousValue = player.leaderstats.Stage.Value

player.leaderstats.Stage.Changed:Connect(function(newValue)
    if newValue > previousValue then
        stagecounter.Parent.Sound:Play()
    end
end)

You can use that, but I don’t think it carries in any parameters for the old OR new value right?

why dont you just bind the sound to the thing incrementing the leaderstat value tho

Thank you so much, I appreciate a lot!

1 Like

i think its the same as changed

This is also another valid option, you could do this too.