#Hitbox not working

1 messages · Page 1 of 1 (latest)

sour prism
#

My serverscript:

voltEvent.OnServerEvent:Connect(function(player)
    local char = player.Character
    if not char then return end

    local hitbox = voltHitbox:Clone()
    hitbox.Parent = workspace
    hitbox.Anchored = false
    hitbox.CanCollide = false
    hitbox.CanTouch = true
    hitbox.CanQuery = true

    -- Weld to blade
    local blade = char:FindFirstChildOfClass("Tool"):WaitForChild("Blade")
    local weld = Instance.new("Weld")
    weld.Part0 = blade
    weld.Part1 = hitbox
    weld.C0 = CFrame.new()
    weld.C1 = CFrame.new()
    weld.Parent = blade

    local touchingParts = workspace:GetPartsInPart(hitbox)
    print("Parts found:", #touchingParts)


    for _, part in ipairs(touchingParts) do
        local char = part.Parent
        local humanoid = char and char:FindFirstChild("Humanoid")
        -- ✅ ignore self
        if humanoid and char ~= player.Character then
            damageModule.DealDamage(player, char, 15)
            print("Hit:", char.Name)
        end
    end

    -- Cleanup after 0.7s
    game.Debris:AddItem(hitbox, 0.7)
end)
#

Module:

#

function DamageModule.DealDamage(attacker, target, amount)
    if not target then return end

    local humanoid = target:FindFirstChild("Humanoid")
    if not humanoid then return end
    if humanoid.Health <= 0 then return end

    -- Deal damage
    humanoid:TakeDamage(amount)

    -- Print debug info
    local attackerName = attacker.Name or "NPC"
    print(attackerName .. " dealt " .. amount .. " damage to " .. target.Name)
end

return DamageModule ```
#

It doesn't detect anything

fast copper
#

Also make sure the hitbox is welded into the right spot. Another issue could be that the hitbox isn’t detecting anything since it might be out of place.