Feel like I’m a beginner all over again. As I do my OOP combat, after using a method someone told me in the previous summary, I seem to struggle with getting a working damage interpretation system going. When I use this function
local DamageInterpretation = {}
DamageInterpretation.__index = DamageInterpretation
local AvailableProperties = {
BlockBreak = "boolean",
WeaponType = "string",
KnockBack = "boolean",
Blockable = "boolean",
AttackType = "string",
Damage = "number",
KBTime = "number",
QiType = "string",
}
function DamageInterpretation.new(properties: {})
return setmetatable({}, DamageInterpretation):_Initialize(properties)
end
function DamageInterpretation:_Initialize(properties: {})
for key, value in pairs(properties) do
local dataType = AvailableProperties[key]
--[[
This step is unnecessary all you need is `self[key] = value`,
this just checks if the type of data is correct/the same and
the key should be added.
]]
if dataType then
if typeof(value) == dataType then
self[key] = value
else
error(("%s must be a type of %s"):format(key, dataType))
end
else
warn("%s can't be added")
end
end
return self
end
The script above is how I attempt to setup the scripts, but then I end up having an issue.
This issue is the result of attempting to use this function
local function damageHum(hum,dmg)
-- if hitchar.Name == "PuppetModel" then return end
local minHp = 0.3
print(hum)
print(dmg)
if hum.Health ~= minHp then
hum.Health = math.clamp(hum.Health - dmg,minHp,math.max(hum.MaxHealth,.15))
else
hum.Health = minHp + 0.3
game:GetService("RunService").Heartbeat:Wait()
hum.Health = minHp
end
end
The thing I tried to solve earlier was to print self, instead began to tell me the issue which said
I was attempting to figure out why damage is now a function (because only now it’s doing that, earlier it was saying that self was nil)
Besides the fact I don’t see the usage of the damageHum script outside of that module, there’s no other reason its not another method.
function DamageInterpretation:Damage(Character, HitHum, HitChar)
print(self)
local DMG = self.Damage
local OGDMG = DMG
if not HitChar then return end
if HitChar:FindFirstChildOfClass("ForceField") then return end
if Character:FindFirstChildOfClass("ForceField") then return end
local function damageHum(hum,dmg)
-- if hitchar.Name == "PuppetModel" then return end
local minHp = 0.3
print(hum)
print(dmg)
if hum.Health ~= minHp then
hum.Health = math.clamp(hum.Health - dmg,minHp,math.max(hum.MaxHealth,.15))
else
hum.Health = minHp + 0.3
game:GetService("RunService").Heartbeat:Wait()
hum.Health = minHp
end
end
if self.KnockBack == true then
local BV = Instance.new("BodyVelocity")
BV.Parent = HitChar:FindFirstChild("HumanoidRootPart")
BV.MaxForce = Vector3.new(100000, 22500, 100000)
BV.P = 33300
BV.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 40
Debris:AddItem(BV, self.KBTime)
end
local Player = Players:GetPlayerFromCharacter(Character)
local ePlayer = Players:GetPlayerFromCharacter(HitChar)
if self.Blockable == true and self.AttackType == "Blunt" then
DMG = DMG/2
end
damageHum(HitHum, DMG)
end
Actually I think the issue is here, you’re calling DamageInterpretation.new(AvailableProperties) but you’re never assigning it to a variable so when you go to call its methods you’re actually passing the DamageInterpretation module as self, not the DamageInterpretation object as self.