#how to destroy hitbox

1 messages · Page 1 of 1 (latest)

blazing salmon
#
local module = {}

local Debris = game:GetService("Debris")

-- шаблон для хитбокса
local part = Instance.new("Part")
part.Anchored = false
part.CanCollide = false
part.Massless = true
part.CastShadow = false
part.Transparency = 1


local box = Instance.new("SelectionBox")
box.LineThickness = 0.02 
box.Color3 = Color3.fromRGB(255, 0, 0) 
box.Adornee = part
box.Parent = part

function module:CreateHitBox(character, size,Damage,Duration)
    local HitBox = part:Clone()
    HitBox.Name = "HitBox"
    HitBox.Size = size
    HitBox.Parent = workspace

    -- привязка к персонажу
    local root = character:FindFirstChild("HumanoidRootPart")
    if not root then
        HitBox:Destroy()
        return
    end

    local Weld = Instance.new("Weld")
    Weld.Part0 = root
    Weld.Part1 = HitBox
    Weld.C0 = CFrame.new(0, 0, -3)
    Weld.Parent = HitBox

    task.spawn(function()
        local params = OverlapParams.new()
        params.FilterType = Enum.RaycastFilterType.Exclude
        params.FilterDescendantsInstances = {character, HitBox}

        local alreadyHit = {}

        while HitBox.Parent do
            local partsCollected = workspace:GetPartsInPart(HitBox,params)
            if partsCollected then
                for _, part in partsCollected do
                    if part.Parent and part.Parent:FindFirstChild("Humanoid") and not alreadyHit[part.Parent] then
                        local targetHit = part.Parent            
                        alreadyHit[targetHit] = true
                        local targetHumanoid: Humanoid = targetHit.Humanoid
                        targetHumanoid:TakeDamage(Damage)
                    end
                end
            end
            task.wait()
        end
    end)
    if Duration then
        Debris:AddItem(HitBox, Duration)
    end
end

function module.DestroyHitBox(char)
    
end


return module```
#

i have this module script that creates a hitbox and deletes it after some time but i want to be able to delete it myself, but with my version of code idk how to do it

keen mango
#

Or use task.delay instead of debris, check if the hitbox exists and then delete else return