01 | local debounce = false |
02 | local value = script.Parent.Parent.Parent.Energy |
03 |
04 | (subtraction detection here) |
05 |
06 | if not debounce then debounce = true |
07 | script.Parent.Transparency = 0.5 |
08 | wait( 0.05 ) |
09 | script.Parent.Transparency = 0.6 |
10 | wait( 0.05 ) |
11 | script.Parent.Transparency = 0.7 |
12 | wait( 0.05 ) |
13 | script.Parent.Transparency = 0.8 |
14 | wait( 0.05 ) |
15 | script.Parent.Transparency = 0.9 |
16 | wait( 0.05 ) |
17 | script.Parent.Transparency = 1 |
18 | wait( 0.05 ) |
19 | script.Disabled = true |
20 | 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.
01 | local value = script.Parent.Parent.Parent.Energy |
02 | local oldValue = value.Value |
03 | local debounce = false |
04 |
05 | value.Changed:Connect( function (newValue) |
06 | if newValue < oldValue and not debounce then |
07 | debounce = true |
08 | for i = 5 , 10 do |
09 | script.Parent.Transparency = i*. 1 |
10 | wait(. 05 ) |
11 | end |
12 | debounce = false |
13 | end |
14 | oldValue = newValue |
15 | end ) |
This might be what you are trying to do
01 | local debounce = false |
02 | local value = script.Parent.Parent.Parent.Energy |
03 |
04 | if not value.Value = = TheNumberItsSetTo then |
05 | if not debounce then debounce = true |
06 | for i = 0.5 , 1 , 0.1 do -- this will help shorten your code without repeating what you said. |
07 | Transparency = i |
08 | wait( 0.05 ) |
09 | end |
10 | end |
11 | end |
If that isn't what you needed, then just comment! But that should work if I didn't miss anything