New Index function not running after setting pre-existing variable

image

local function newindex(a,b,c)
	if rawget(a, "Wrapped") ~= nil then
		local result;
		local success;
		success, result = pcall(function()
			result = a.Wrapped[b];
		end)
		if success then
			a.Wrapped[b] = c;
			return;
		end
	end
	if a._Properties then
		if a._Properties[b] ~= nil then -- If this is a registered property, then change it and fire event.
			if a._Clamps[b] then
				if c < a._Clamps[b][1] then
					c = a._Clamps[b][1];
				end
				if c > a._Clamps[b][2] then
					c = a._Clamps[b][2];
				end
			end
			a._PropertyEvents[b]:Fire(c, a._Properties[b]);
			rawset(a._Properties, b, c);
			return;
		end
	end
	if rawget(a, "_Is_Object") == true then
		a.Changed:Fire(b, c, a[b]);
	end
	rawset(a,b,c);
end

Towards the bottom of the index function you’ll see I have “a.Changed:Fire” and I would like to fire this every time a variable is changed in this table. Yet, it is only changed the first time you set myTest.Hi to something. For some reason, changing an already existing variable doesn’t run the newindex function.

Here is where I set the index and newindex of the new table.
image

doesn’t the __newindev method fire only when the element is nil? changing the value of one of the elements wouldn’t fire the __newindev method.

1 Like

Brain fart! Thanks for reminding me.

No worries! anytime :smiley: have fun scripting :+1:

1 Like