Detecting Changes in tables

Is it possible to detect changes in tables
I need to be able to track changes without a loop because this would be done hundreds of times any ideas

i think there no changed connection that for table variable

so for other way is use this

local db = false
local prev_time = tick()
local data_table = {}
local prev_table_length = #data_table

task.spawn(function()
RunService.Heartbeat:Connect(function()
if db == false and tonumber(tick() - prev_time) >= 0.1 then
db = true
if tonumber(#data_table) ~= tonumber(prev_table_length) then
local msg = “Data Table just changed [Old Len: %s] [New Len: %s]”
warn(string.format(msg, prev_table_length, #data_table))
prev_table_length = tonumber(#data_table)
end
prev_time = tick()
db = true
end
end)
end)

for i=1,10 do
table.insert(data_table, Random.new():NextInteger(1, tonumber(#data_table+i)^1.75))
task.wait(1)
end

Here is a constructor, taken from the Lua reference manual, for a read only table:

function Class:immutable(t)
	local proxy = {}
	local mt = {
		__index = t,
		__newindex = function(t, k, v)
			error("attempt to update a read-only table", 2)
		end,
	}
	setmetatable(proxy, mt)
	return proxy
end

1 Like