How to check how much a value changed?

I wanted to check how much a value changed so I can add it to a different variable but don’t exactly know how.

local x = 0
local y = Instance.new("IntValue", workspace)
y:GetPropertyChangedSignal("Value"):Connect(function()
x += -- amount y has changed from the last time
end)
1 Like
local x = 0
local oldval = nil
local y = Instance.new("IntValue", workspace)
y:GetPropertyChangedSignal("Value"):Connect(function()
if oldval ~= nil and type(oldval) == "number" then
x += y.Value - oldval-- amount y has changed from the last time
end
oldval = y.Value
end)

Forgive the bad indenting, I wrote the script in the message poster.
Keep in mind this would only work after the first time the value has changed and only if the value changed to be higher. You can make exceptions for this by using < and >.
Good luck!

3 Likes