DevFoll
(DevFoll)
October 13, 2023, 12:20pm
#1
I’m making a combat script and i’m gonna use oop for it but the issue is when i call self.Character or anything in the metatable it is nil. When i print self
[“Attack”] = “function”,
[“SetMetatable”] = “function”,
[“__index”] = ▼ {
[“Attack”] = “function”,
[“SetMetatable”] = “function”,
[“__index”] = “*** cycle table reference detected ***”
}
this is what shows up.
CombatEvent.OnServerEvent:Connect(function(Player, AttackType)
local Combat = CombatManager.SetMetatable()
Combat.Character = Player.Character
Combat.AttackType = AttackType
Combat.StopTime = .34
Combat.StartTime = .08
Combat.MaxCombo = 4
CombatManager:Attack()
end)
local module = {}
module.__index = module
function module.SetMetatable()
return setmetatable({
AttackType = "m1",
Damage = 0,
HitboxSize = Vector3.new(6,6,6),
StartTime = .08,
StopTime = .34,
Character = nil,
MaxCombo = 4,
}, module)
end
function module:Attack()
local Character = self.Character
local Humanoid = Character.Humanoid
local RootPart = Humanoid.RootPart
local Animator = Humanoid.Animator
2 Likes
yo9sa
(yosa)
October 13, 2023, 12:32pm
#2
Tell me, why do you need the module.SetMetatable() function if you can create a metable without it?
DevFoll
(DevFoll)
October 13, 2023, 12:42pm
#3
i use it to like set the settings of the combat attack depending on which weapon i use
M1APOP
(duckity)
October 13, 2023, 12:43pm
#4
Your issue could be that you set Character
to nil in the script.
function module.SetMetatable()
return setmetatable({
AttackType = "m1",
Damage = 0,
HitboxSize = Vector3.new(6,6,6),
StartTime = .08,
StopTime = .34,
Character = nil, -- You're setting self.Character to nil.
MaxCombo = 4,
}, module)
end
DevFoll
(DevFoll)
October 13, 2023, 12:44pm
#5
Yes but i believe it’s supposed to change once i set the metatable
M1APOP
(duckity)
October 13, 2023, 12:45pm
#6
Could you show some of the script that’s using the SetMetatable()
function?
DevFoll
(DevFoll)
October 13, 2023, 12:46pm
#7
it’s the first script i showcased
CombatEvent.OnServerEvent:Connect(function(Player, AttackType)
local Combat = CombatManager.SetMetatable()
Combat.Character = Player.Character
Combat.AttackType = AttackType
Combat.StopTime = .34
Combat.StartTime = .08
Combat.MaxCombo = 4
CombatManager:Attack()
end)
yo9sa
(yosa)
October 13, 2023, 12:48pm
#8
Most likely nil because you are accessing a metatable and not a regular table.
function module:Attack()
local Character = self.Character
local Humanoid = Character.Humanoid
local RootPart = Humanoid.RootPart
local Animator = Humanoid.Animator
Try to change following scripts:
function module.Attack(self)
local Character = self.Character
local Humanoid = Character.Humanoid
local RootPart = Humanoid.RootPart
local Animator = Humanoid.Animator
CombatEvent.OnServerEvent:Connect(function(Player, AttackType)
local Combat = CombatManager.SetMetatable()
Combat.Character = Player.Character
Combat.AttackType = AttackType
Combat.StopTime = .34
Combat.StartTime = .08
Combat.MaxCombo = 4
CombatManager.Attack(Combat)
end)
DevFoll:
CombatManager:Attack()
You’re not calling Attack
on the object you created.
You’re calling the method of the CombatManager class, not the object, try to use
Combat:Attack()
1 Like
system
(system)
Closed
October 27, 2023, 1:02pm
#11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.