Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

detecting if a number was subtracted in a value?

Asked by 6 years ago
01local debounce = false
02local 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.

0
Check waffles answer, sounds like its what you need. DinozCreates 1070 — 6y

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
6 years ago

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.

01local value = script.Parent.Parent.Parent.Energy
02local oldValue = value.Value
03local debounce = false
04 
05value.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
15end)
0
it works, thanks. mantorok4866 201 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

This might be what you are trying to do

01local debounce = false
02local  value = script.Parent.Parent.Parent.Energy
03 
04if 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
11end

If that isn't what you needed, then just comment! But that should work if I didn't miss anything

0
yea its not quite what I need, for example, the value starts at 100, I need the script to run once every time 1 is subtracted from the value. mantorok4866 201 — 6y

Answer this question