#hitbox bug

1 messages · Page 1 of 1 (latest)

crisp quarry
#

the hitbox doesn't damage instantly so that is a problem for me, here is the code:

(local bF = script:WaitForChild("Function")

bF.OnInvoke = function()
    if not M1Debounce then
        M1Debounce = true
        
        local punchsd = script.Parent.Parent:FindFirstChild("Punch")
        punchsd:Play()
        
        local hitbox = Instance.new("Part")
        hitbox.Material = "ForceField"
        hitbox.Transparency = 0.3
        hitbox.Color = Color3.fromRGB(255, 0, 0)
        hitbox.Massless = false
        hitbox.CanCollide = false
        hitbox.Anchored = true
        hitbox.Size = Vector3.new(4, 5.339, 2.613)
        hitbox.Parent = workspace
        hitbox.CFrame = script.Parent.Parent:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, -5)
        
        
        
        
        
        
        m1preformed += 1
        currentM1 += 1
        
        local correspondingM1Anim = rsanim:FindFirstChild('Punch ('..currentM1..')')
        local M1Track = animator:LoadAnimation(correspondingM1Anim)
        
        M1Track:Play()
        
        hitbox.TouchEnded:Connect(function(otherpart)
            local parent = otherpart.Parent
            

            -- Ensure the parent object has Attributes property
            
            

            local attributes = parent:FindFirstChild("Attributes")
            
            -- Check if Attributes contains the specified values
            local blocking = attributes:FindFirstChild("Blocking")
            local blockbar = attributes:FindFirstChild("Blockbar")

            -- Check if Attributes properties exist
            

            local blockingValue = blocking.Value
            local blockbarValue = blockbar.Value
            local humanoid = parent:FindFirstChildOfClass("Humanoid")

            
            -- Ensure hitbox is not affecting the player or specific parts
            
            
            local value = tonumber(blockbar.Value)

        
                
            
            -- Handle Blocking = "On"
            if parent.Name == plrname then return end     
                if blockingValue == "On" then
                
                    if value and (value < 0 or value == 0) then
                        blocking.Value = "Off"
                        hitbox:Destroy()
                    elseif blockbarValue ~= 0 then
                        blockbar.Value = blockbar.Value-dmg
                        hitbox:Destroy()
                    end



                    -- Handle Blocking = "Parry"
                elseif blockingValue == "Parry" then
                    
                    script.Enabled = false
                    script.Parent.Parent:WaitForChild("HumanoidRootPart").Anchored = true
                    hitbox:Destroy()
                    task.wait(1)
                    script.Parent.Parent:WaitForChild("HumanoidRootPart").Anchored = false
                    script.Enabled = true
                    -- Handle Blocking = "Off"
                elseif blockingValue == "Off" then
                    

                    humanoid:TakeDamage(dmg)
                    hitbox:Destroy()
                    wait(0.4)

                else
                    print("Invalid blocking value")
                    hitbox:Destroy()
                    return
                end
            
        end)
        
        task.wait(M1Track.Length -0.1)
        task.spawn(function()
            local OldM1Preformed = m1preformed
            task.wait(waitBeforeReset)
            if OldM1Preformed == m1preformed then
                currentM1 = 0
            end
            
        end)
        
        if currentM1 == 4 then
            task.wait(comboEndCooldown)
            currentM1 = 0
        end
        
        M1Debounce = false
        
    end
end)

please help

livid ospreyBOT
#

studio** You are now Level 2! **studio

peak elm
#

Using touch ended for a hitbox is… creative

It only fires when a part of the other rig stopped touched the hitbox (i.e. moved away from the hitbox).
I would advice you to use something like touched, but that’s still not ideal. It’s best to look into getpartsinpart/getpartsinbound for some better hitboxes to be frank

crisp quarry
peak elm
#

Just using touch ended doesn’t help with that. If the other player walks out of the hitbox, then it will still deal damage multiple times

crisp quarry
#

bruhh i cant get u i feel u r to smart can u say it in codes so i can understand like any showrt i will appreicate it please my english is bad

peak elm
crisp quarry
#

Thanks man i get it now