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

2 comments
So 'entity' was set wrong? Just clarifying, I am personally trying to learn how to use metatables.
Uh?