So I have an BaseNPC system where calling BaseNPC.new will call init() which then starts the loop process. Everything works as intended when I just spawn the normal BaseNPC but when I try to inherit the methods some of the functions mystery stops working like self:Destroy and self:MoveToPlayer. But as soon as I slightly modify the names to self:Destroys and self:MoveToPlayers the functions work again for other classes… I have no idea why changing the name made them work when other classes inherit the methods.
function BaseNPC.new(Cframe, Wave)
local self = setmetatable({}, BaseNPC)
self._Model = Properties.model:Clone()
self._Humanoid = self._Model.Humanoid or self._Model:FindFirstChild("Humanoid")
self._Animator = self._Humanoid:FindFirstChild("Animator")
self._Cframe = Cframe or CFrame.new()
self._Connections = {}
--scaling here
self.AttackDamage = self.AttackDamage * (1 + (self.DamageScale * Wave))
self.Health = self.Health * (1+ (self.HealthScale * Wave))
self.Gold = self.Gold * (1+ (self.GoldScale * Wave))
self.Experience = self.Experience * (1+ (self.ExperienceScale * Wave))
self:Init()
return self
end
function BaseNPC:Loop() --scuffed but works ig
coroutine.wrap(function()
while self._Humanoid:GetState() ~= Enum.HumanoidStateType.Dead do
local player = PS:FindFirstChild(self.Target)
if not player or not player.Character or not player.Character:FindFirstChild("Humanoid") or player.Character.Humanoid.Health <= 0 then
return
end
local HRP = player.Character:FindFirstChild("HumanoidRootPart")
local ModelHRP = self._Model:FindFirstChild("HumanoidRootPart")
if not ModelHRP or not HRP then
task.wait(0.25)
print("NO HRP FOUND")
continue
end
local PlayerPosition = HRP.Position
local ModelPosition = ModelHRP.Position
self:MoveToPlayers(player, ModelPosition, PlayerPosition)
task.wait(0.25)
end
end)()
end
function BaseNPC:Init()
--Tags,spawning and network, instances
CS:AddTag(self._Model, self.Tag)
self:AlignOrientationSetUp()
self._Model.Parent = workspace.NPCFolder
self._Model:SetPrimaryPartCFrame(self._Cframe)
for _, parts in pairs(self._Model:GetDescendants()) do
if parts:IsA("BasePart") then
parts:SetNetworkOwner(nil)
parts.CollisionGroup = CollisionGroupName
end
end
--Direct Humanoid "Attributes"
self._Humanoid.MaxHealth = self.Health
self._Humanoid.Health = self.Health
self._Humanoid.WalkSpeed = self.WalkSpeed
--CharacterAttributes
for _, player in PS:GetPlayers() do
self.Target = player.Name
end
self._Model:SetAttribute("Stunned", false)
--Connections maybe
self._Connections["HumanoidConnection"] = self._Humanoid.Died:Connect(function()
self._Connections["UpdateTableBindable"] = NPCUpdateTable_BE:Fire(self._Model)
self:Destroys()
end)
self._Connections["StunConnection"] = self._Model:GetAttributeChangedSignal("Stunned"):Connect(function() --do later
self:onStun()
end)
self:Loop()
end
BaseKnight.__index = BaseKnight
setmetatable(BaseKnight, MainNPC)
function BaseKnight.new(Cframe : CFrame, Wave : number)
local self = setmetatable(MainNPC.new(Cframe, Wave), BaseKnight)
return self
end