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

How do i detect if a number value increases or decreases?

Asked by 4 years ago

I want to check if a number value changed but i also want to check if it went up or down.

SUNMASS.Changed:Connect(function()
    if (SUNMASS.Value + (DEFAULTRADIUS - 1)) > DEFAULTRADIUS then
        local differance = (SUNMASS.Value + (DEFAULTRADIUS - 1)) - DEFAULTRADIUS
        RADIUS.Value = RADIUS.Value + differance
    end
    wait(0.5)
end)

0
https://developer.roblox.com/en-us/api-reference/event/IntValue/Changed it is a link to the changed event, I had a brief look at it so I don’t know too much about it but it has 1 parameter 123nabilben123 499 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
local sv = SUNMASS
SUNMASS.Changed:Connect(function()
    if SUNMASS > sv then
        print("decreases")
    elseif SUNMASS < sv then
        print("increases")
    end
end)

Ad
Log in to vote
0
Answered by 4 years ago

hi, back here! I figured it out. So we have to use a small formula that subtracts the changes value from the new value.

So likes this:

local function valueChanged(num)
     local determinatial = SUNMASS.Value - num

      if SUNMASS.Value < determinatial then
            return “bigger”
      else
            return “smaller”
      end
end

SUNMASS.Changed:Connect(valueChanged)

Answer this question