#weapon flinging and teleporting me

1 messages · Page 1 of 1 (latest)

proud plume
#

ok so basically I extended a hitbox for my spear weapon and now for the first time I equip it I get teleported to its location in workspace and whenever I swing it i get flung. I think this is because the hitbox collides with the ground but I set the hitbox to massless, unanchored, transparency 1, and cancollide false, here is my code:

    -- Hitbox detection
    local function onTouched(part)
        local char = part:FindFirstAncestorOfClass("Model")
        if not char or char == player.Character or debounce[char] then return end

        local humanoid = char:FindFirstChildOfClass("Humanoid")
        if humanoid and humanoid.Health > 0 then
            humanoid:TakeDamage(DAMAGE)
            debounce[char] = true
        end
    end

    local conn = hitbox.Touched:Connect(onTouched)

    -- Enable hitbox for short window
    task.delay(SWING_WINDOW, function()
        if conn then conn:Disconnect() end
    end)
end

end)

hollow yokeBOT
#

studio** You are now Level 1! **studio

knotty adder
#

Did you make the model uncollidible too?

obtuse zealot
# proud plume ok so basically I extended a hitbox for my spear weapon and now for the first ti...
local SWING_WINDOW = 0.2  -- adjust as needed
local HITBOX_SIZE = Vector3.new(4, 4, 4)  -- tweak size
local HITBOX_OFFSET = Vector3.new(0, 0, -3)  -- adjust for how far forward your spear is

local function performSwing()
    local root = player.Character.PrimaryPart
    local center = root.CFrame * CFrame.new(HITBOX_OFFSET)
    local region = Region3.new(center.Position - HITBOX_SIZE/2, center.Position + HITBOX_SIZE/2)
    local parts = workspace:FindPartsInRegion3WithIgnoreList(region, {player.Character}, 100)

    local damaged = {}
    for _, part in ipairs(parts) do
        local char = part:FindFirstAncestorOfClass("Model")
        local humanoid = char and char:FindFirstChildOfClass("Humanoid")
        if humanoid and humanoid.Health > 0 and not damaged[char] then
            humanoid:TakeDamage(DAMAGE)
            damaged[char] = true
        end
    end
end

-- Call this instead of physics-based hitbox
performSwing()```
#

you could also anchro the hitbox and use touch detection like this

hitbox.Massless = true
hitbox.Anchored = true  -- prevents all physics movement

local conn = hitbox.Touched:Connect(function(part)
    -- your damage logic here
end)

task.delay(SWING_WINDOW, function()
    if conn then conn:Disconnect() end
end)```