Getting hit outside of hitboxes

I have a hitbox system and my newly made barrage ability(It looks goofy I know). Anyway for some reason, once I enter the hitbox, event if I go out it will continue to hit me. At first I thought the issue was that the detection code would only run once then the loop would continue using the objects detected but that is not the case, the loop redetects new Intakehitboxes(the red ones) every time it runs so it should not be damaging the player. Here is the code that is ran when the attack begins and its purpose is to find any “IntakeHitBoxes” within the attacks hitbox(the green one) and send values about the specific attack to the IntakeScript within all IntakeHitboxes :

if action == "Barrage" then

			stopBigAttack = false
			stopBarrage = false

			if detectors.CanBarrage.Value and detectors.WeaponEquipped.Value and cooldowns.Barrage.Value == false then

				StopTracks()
				Barrage:Play()

				detectors.IsBarraging.Value = true
				detectors.CanDash.Value = false
				detectors.CanBlock.Value = false
				detectors.CanAttack.Value = false
				detectors.CanEquip.Value = false
				detectors.CanDeflect.Value =  false
				humanoid.WalkSpeed = 4
				humanoid.JumpPower = 0

				local repitions = 0
				
				local hitbox = character.HitBoxes.BasicM1Box
				local IntakeHitbox = character.HitBoxes.IntakeHitBox
				local params = OverlapParams.new()
				params:AddToFilter(IntakeHitbox)

				while true do

					task.wait(0.1)

					if stopBigAttack or stopBarrage or repitions == 50 then

						Barrage:Stop()
						stopBarrage = false
						break

					end

					repitions += 1
					
					local parts = game.Workspace:GetPartsInPart(hitbox,params) do

						for i,part in pairs(parts) do

							if part.Name == "IntakeHitBox" then
								local newChar = part.Parent.Parent
								local IntakeScript = require(part.IntakeScriptModule)

								IntakeScript.DamageAmount = 0.8
								IntakeScript.KnockbackPower = 1
								IntakeScript.UpKnockback = 0
								IntakeScript.PlayerWhoHit = character
								IntakeScript.Ragdoll = false
								IntakeScript.RagdollTime = 0
								IntakeScript.BlockBreaks = false
								IntakeScript.CanParry = false
								IntakeScript.BlockAdditions = 100
								IntakeScript.Iframes = 0
								IntakeScript.StunType = true
								IntakeScript.StunTime = 300
								IntakeScript.OnlyOneCanHit = true
								IntakeScript.OnlyOneTime = 300
								IntakeScript.ReceiveDamage()


							end

						end

					end

				end

				detectors.IsBarraging.Value = false
				cooldownTimers.Barrage.Value = 15000
				MovementControl.WalkSpeed.Value = 50
				MovementControl.JumpPower.Value = 50
				detectorTimers.CanDash.Value = 50
				detectorTimers.CanAttack.Value = 50
				detectorTimers.CanEquip.Value = 50
				detectorTimers.CanBlock.Value = 50
				detectorTimers.CanDeflect.Value = 50

			end

		end

Don’t worry about the rest of the code, the only important part is when I use :GetPartsInPart.

Getting Hit outside of hitbox - Clipped with Medal.tv is a video showing the issue

Maybe instead of using parts, try using Region3 or Raycasting

Region3 is deprecated and alot harder to use, OP should use :GetPartsInBound() which is new and works better for hitboxes.

I don’t know if this will fix it, but have you tried adding a simple debounce on line 2? It would look like this for example:

local deb = 0

if action == "Barrage" then
    if deb == 1 then
    else
        deb = 0
        -- Run your code here
        task.wait(0.05)
        deb = 1
    end
end

Edit: Also try resetting the parts variable at the last line of the code, so just:

    local parts = {}
end

The debounce had no effect but I will try reset the parts.

Last piece of advice I can offer you is to just spam print(1) and print(2) etc everywhere and see what it is doing and when so you can bug fix.

Setting parts to nothing didn’t work either, but when I added the Hitbox to the param filter, obviously the player only got hit once so that confirms it is not a loop issue inside of the IntakeScript. Also maybe a piece of important info is that only NPCs have this issue and it works perfectly when a player uses the move.

Just figured out that it is a physics issue with the knockback as when I turned the knockback off, it worked perfectly fine. For some reason when the knockback is applied in very short intervals it bugs out and doesn’t register the player moving on the server. Here is the code for the knockback if you could help me fix it please :

--Gives the player Knockback
					if Values.KnockbackPower ~= 0 or Values.UpKnockback ~= 0 then

						local Attachment = Instance.new("Attachment",rootPart)
						local LinearVelocity = Instance.new("LinearVelocity",rootPart)

						LinearVelocity.MaxForce = 100000
						LinearVelocity.VectorVelocity = (Values.PlayerWhoHit.HumanoidRootPart.CFrame.LookVector * Values.KnockbackPower) + Vector3.new(0,Values.UpKnockback,0)
						LinearVelocity.Attachment0 = Attachment
						Values.KnockbackPower = 0
						Values.UpKnockback = 0
						DebrisService:AddItem(Attachment,0.1)
						DebrisService:AddItem(LinearVelocity,0.1)
						
					end

you can modify the code to continuously update the parts list by moving the GetPartsInPart function inside the loop.

while true do
    task.wait(0.1)

    if stopBigAttack or stopBarrage or repitions == 50 then
        Barrage:Stop()
        stopBarrage = false
        break
    end

    repitions += 1

    local parts = game.Workspace:GetPartsInPart(hitbox, params)

    for i, part in pairs(parts) do
        if part.Name == "IntakeHitBox" then
            local newChar = part.Parent.Parent
            local IntakeScript = require(part.IntakeScriptModule)

            IntakeScript.DamageAmount = 0.8
            IntakeScript.KnockbackPower = 1
            IntakeScript.UpKnockback = 0
            IntakeScript.PlayerWhoHit = character
            IntakeScript.Ragdoll = false
            IntakeScript.RagdollTime = 0
            IntakeScript.BlockBreaks = false
            IntakeScript.CanParry = false
            IntakeScript.BlockAdditions = 100
            IntakeScript.Iframes = 0
            IntakeScript.StunType = true
            IntakeScript.StunTime = 300
            IntakeScript.OnlyOneCanHit = true
            IntakeScript.OnlyOneTime = 300
            IntakeScript.ReceiveDamage()
        end
    end
end```

It already is in the loop in my original code.