Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

detecting if a number was subtracted in a value?

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.

1 comment

0

Check waffles answer, sounds like its what you need.

2 answers

✓ Accepted answer

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)

1 comment

0

it works, thanks.

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.