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

[SOLVED] What is the best way to tell if a value has been subtracted from?

Asked by
nanaluk01 247 Moderation Voter
7 years ago
Edited 7 years ago

What is the best way to tell if a value has been subtracted from?

I have some ideas like this one, for instance:

local number = game.Workspace.Number
local prevnumber = number.Value

number.Changed:connect(function()
    if number.Value < prevnumber then
        print("Number is smaller than prevnumber")
    end
end)

But what I really want to know is if there is any other more efficient way to tell if a value has ben subtracted from.

Any help is greatly appreciated!

1 answer

Log in to vote
1
Answered by 7 years ago

No

There is genuinely no better way to tell if it has been subtracted from than to check. Mind, your example code is wrong.

local num = workspace.Number;
local prev = num.Value;

num.Changed:connect(function(val)
  if prev > val then
    -- Subtracted from
  end
  prev = val; -- Make sure that you update the old value
end);
0
Thanks, but I already figured it out. :-) nanaluk01 247 — 7y
Ad

Answer this question