Check when table has been modified

The title pretty much explains it all, is there a way to check when a table has been changed and then call a function.

You need to use metatables. Here is an example:

local youtable = {}
local metatable = {}
metatable.__newindex = function(_, index, value)
	metatable[index]=value
	if not value then
		print(`Deleted {index}`)
		return
	end
	print(`Changed {index} to {value}`)
end
setmetatable(youtable, metatable)
youtable.x = 5
youtable.x = 7
youtable.x = nil

image
Docs: Metatables | Roblox Creator Documentation
All you need to know about Metatables and Metamethods

2 Likes

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