The error is that the values assigned in the new method are nil to other methods of the class. How can I have the values not be nil when a method requests for them? As when I spawn a NPC and ask for the CFrame, it states self is nil.
local NPC= {} NPC._index = NPC function NPC.new(model) local entity = setmetatable({}, NPC) for index, value in pairs (NPC) do entity[index] = value end entity.Self = model entity.Settings = model:WaitForChild("Configurations") entity["Mind"] = model.Mind return entity end function NPC:GetCFrame() local humanoidRootPart = self.Self:FindFirstChild("humanoidRootPart") if humanoidRootPart and humanoidRootPart:IsA("BasePart") then print(humanoidRootPart.CFrame) return humanoidRootPart.CFrame else return CFrame.new() end end function NPC:Initialize() NPC:GetCFrame() end return NPC
The issue was - shockingly - due to the the metatable being set incorrectly. It was: setmetatable(NPC, {}) which causes the methods to be able to grab their own values.