local debounce = false local value = script.Parent.Parent.Parent.Energy (subtraction detection here) if not debounce then debounce = true script.Parent.Transparency = 0.5 wait(0.05) script.Parent.Transparency = 0.6 wait(0.05) script.Parent.Transparency = 0.7 wait(0.05) script.Parent.Transparency = 0.8 wait(0.05) script.Parent.Transparency = 0.9 wait(0.05) script.Parent.Transparency = 1 wait(0.05) script.Disabled = true end
Im trying to get this script to run only when an intvalue's number was reduced but I dont know exactly how to set this up.
To tell when it decreases, record the initial value and listen to the Changed event, and see when the new value is less than the recorded old value.
local value = script.Parent.Parent.Parent.Energy local oldValue = value.Value local debounce = false value.Changed:Connect(function(newValue) if newValue < oldValue and not debounce then debounce = true for i = 5, 10 do script.Parent.Transparency = i*.1 wait(.05) end debounce = false end oldValue = newValue end)
This might be what you are trying to do
local debounce = false local value = script.Parent.Parent.Parent.Energy if not value.Value == TheNumberItsSetTo then if not debounce then debounce = true for i = 0.5, 1, 0.1 do -- this will help shorten your code without repeating what you said. Transparency = i wait(0.05) end end end
If that isn't what you needed, then just comment! But that should work if I didn't miss anything