Hey! I was following a certain tutorial and script. I wanted to make an ability for my PVP fighting game.
I was just wondering the following question:
function newHitbox(character, size, offset, damage, linger, kb)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
local weld = Instance.new("WeldConstraint", hrp)
local hitbox = Instance.new("Part")
weld.Part0 = hrp
weld.Part1 = hitbox
hitbox.Transparency = 1
hitbox.CanCollide = false
hitbox.CanQuery = false
hitbox.Massless = true
hitbox.Size = size
hitbox.CFrame = hrp.CFrame + hrp.CFrame.LookVector * offset.X + Vector3.new(0,offset.Y)
hitbox.Parent = character
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") == nil then return end
for _, v in pairs(hitbox:GetChildren()) do
if v:IsA("ObjectValue") then
if v.Value == hit.Parent then return end
end
end
local hitCounter = Instance.new("ObjectValue", hitbox)
hitCounter.Value = hit.Parent
hit.Parent.Humanoid:TakeDamage(damage)
if kb <= 0 then return end
knockback(hit.Parent, character, kb)
end)
game.Debris:AddItem(hitbox, linger)
end
In the last lines, I was wondering if I should use Instance:Destroy() or game.Debris:AddItem. Just so game.Debris:AddItem doesn’t lag out my game a lot if players use it alot.