Need help with checking the rate of change

Writing a piece of code that checks what change of a value is, and for some reason it just does not want to work.

current code is this:

for _,values in pairs(serverStorage.Values.ReactorValues:GetChildren()) do
	if values:IsA("ValueBase") then
		values.Changed:Connect(function()
		
			for _,elms in pairs(Monvalues.Holder:GetChildren()) do
				if elms.Name == values.Name then					
					
					--// last value
					local change

					for i,v in lastTemps do
						if i == elms.Name then
							change = values.Value - v
							v = values.Value

						end
					end

					print(change)
					--// and finally updating the text
					txtmodule.updateTxt(elms.Info,values.Value,values.unit.Value,change)

				end
			end
		end)
	end
	
end

issue is, the change value is just set to whatever the current value value is, and I have no clue why. Anyone able to help me out with this?

(for example, if the value before was 30, and the value now is 40, the change value is just going to say 40).

v = values.Value

I believe v in this case is a local variable within the loop. Have you tried doing:

lastTemps[i] = values.Value
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.