C Stack overflow error

Creature.__newindex = function(Table , Key , Value) 
	if Key == "Energy" or Key == "Health" then
		Table[Key] = math.clamp(Value , 0 , math.huge)  
	elseif Key == "StatusEffect" and Table.StatusEffect == nil then
		Table[Key] = Value
	else
		Table[Key] = Value
	end
end

I can’t find any reason why the error appears.

You must use rawset in order to avoid retriggering the __newindex call.

rawset(Table, key, math.clamp(Value, 0, math.huge)
1 Like