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 5 years ago
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.

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

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
5 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.

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)
0
it works, thanks. mantorok4866 201 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

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 — 5y

Answer this question