How would I save a previous number if it changed?

So what I’m trying to do is save a number, then if the number gets changed, it saves the previous number to another variable. I’ve been trying to figure out how to do this but can’t figure it out.

local currentValue = nil
local previousValue = nil

local SetValue = function(value)
	previousValue = currentValue
	currentValue = value
end

SetValue(5)
SetValue(25)

print("previous:", previousValue)
print("current:", currentValue)
2 Likes