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

Why is this value doing this?

Asked by 9 years ago

I have a number value that I subtract a given number from when a mouse is clicked and just automatically. The problem is, though, that occasionally I subtract a number more than once very close in time to each other in two different scripts. The value, instead of combining both numbers that are being subtracted, only subtracts one of the numbers. Why is this happening?

Script #1

local value = game.Workspace.NumberValue.Value -- let's assume value is 30
local randomNumber = 5

function Down(mouse) -- assuming the mouse is clicked very close to the time before randomNumberTwo is subtracted from the value in script #2 and very close to the time  after randomNumberTwo is subtracted
    value = value - randomNumber
    print(value)
end

function Selected(mouse)
    mouse.Button1Down:connect(function() Down(mouse) end)
end

-- Output = 20

Script #2

local randomNumberTwo = 10
local value = game.Workspace.NumberValue.Value -- since only 1 mouse click has occured, the value should now be 25

wait(3)
value = value - randomNumberTwo
print(value)

-- Output = 20

Answer this question