How to grab the amount a value has changed?

I am trying to make a GUI that shows how much money you collected/lost when it happens (example below) but I am having trouble trying to figure out how I am going to grab that value.

If you could provide an example of how I could do this that would be appreciated.

example:

Screen Shot 2022-03-15 at 12.51.04 PM

3 Likes

Use

Value.Changed

In Code:

Value.Changed:Connect(function(changed)
   script.Parent.Text = "$+"..str(changed)
end)

Hope it helped

2 Likes
local lastValue = money.Value
money.Changed:Connect(function(newValue)
	print("Changed by", newValue - lastValue)
	lastValue = newValue
end)
5 Likes

You’d need to store the previous value before it was changed as the example above demonstrated, to log all changes you could do the following.

local value = workspace.Value --Example value instance.

local oldValues = {}

value.Changed:Connect(function(newValue)
	print("Value changed from "..oldValues[#oldValues].." to "..newValue.."!")
	table.insert(oldValues, newValue)
end)
3 Likes
local value = workspace.Value
local last_value = value.Value

value:GetPropertyChangedSignal("Value"):Connect(function()
local difference = value.Value - last_value
local prefix = value.Value < last_value and "-" or "+"

local text = prefix..difference

print(text) -- if the value was subtracted by 5 it should print "-5"

last_value = value.Value
end)
1 Like

Thank you this worked!

also thank you @Forummer, @OceanTubez, and @SaturdayScandal