I am trying to use classes for my enemies system but I cannot get the code working for the life of me
My problem is that the Monster
class is not registering anything from the Skeleton
class, so when I set the health, model etc… it doesn’t actually set it
I’ve been changing around and modifying my code for hours and it still doesn’t work, so I’m asking for your help
My current code:
-- Monster.lua
local Monster = {}
Monster.__index = Monster
function Monster.new(model, ...)
local monster = {}
setmetatable(monster, Monster)
local args = {...}
-- Initialise variables
for key,value in pairs(args) do
monster[key] = value
end
-- Default values
monster.health = monster.health or 10
monster.detect_distance = monster.detect_distance or 20
monster.model = model or monster.model
return monster
end
-- Metamethods...
return Monster
-- Skeleton.lua
local Monster = require(game.ReplicatedStorage.Monster)
local Skeleton = {}
setmetatable(Skeleton, Monster)
Skeleton.__index = Skeleton
function Skeleton.new(Model, ...)
local skeleton = Monster.new(...)
setmetatable(skeleton, Skeleton)
skeleton.health = health
skeleton.detect_distance = detect_distance
skeleton.model = Model
skeleton:Initialise(...)
return skeleton
end
-- More metamethods...
return Skeleton
In the Monster
class I have a function I use every frame so I set it up to print self
and it returned:
{
["Initialise"] = "function",
["__index"] = "*** cycle table reference detected ***",
["attackTick"] = "function",
["idleTick"] = "function",
["new"] = "function",
["target"] = Puzzled3d,
["tick"] = "function"
}
Which is fully Skeleton
and no Monster
!
And, there should be health
, detect_distance
and model
but they’re nowhere to be seen!
Does anyone know how to make this work? I am extremely stumped