Hitbox.Touched only works when its massless

Im trying to make a part spawn in multiple times in order to make a barrage move, i made it so it spawns in the player and reaches forward, but when trying to make it deal damage, the touch doesnt register.
I tried multiple things, made sure cantouch is true, but it only detected the touch when i disabled massless and moved around sporadically near a dummy, and only sometimes.
How can i make the part register a humanoid has touched it?

                                while attack do
				character.Humanoid.WalkSpeed = 3
				local newhitbox = Instance.new("Part")
				newhitbox.Name = "hitbox"
				newhitbox.CFrame = character.HumanoidRootPart.CFrame
				newhitbox.Anchored = false
				newhitbox.CanTouch = true
				newhitbox.CanCollide = false
				newhitbox.CanQuery = true
				newhitbox.Transparency = 0.55
				newhitbox.Color = Color3.new(1, 0, 0)
				newhitbox.Parent = character
				newhitbox.Size = Vector3.new(4.2,5,6.69)
				local w = Instance.new("Weld",newhitbox)
				w.Part0 = newhitbox
				w.Part1 = character.HumanoidRootPart
				w.C1 = CFrame.new(0,0,-2.89)
				game.Debris:AddItem(newhitbox,2)
				wait(2)

			newhitbox.Touched:Connect(function()
                        print("touched")
end)
			end	

this is my first post, so i hope the formatting works.

Try this:

while attack do
	character.Humanoid.WalkSpeed = 3
	
	local newhitbox = Instance.new("Part")
	newhitbox.Name = "hitbox"
	newhitbox.CFrame = character.HumanoidRootPart.CFrame
	newhitbox.Anchored = false
	newhitbox.CanTouch = true
	newhitbox.CanCollide = false
	newhitbox.CanQuery = true
	newhitbox.Transparency = 0.55
	newhitbox.Color = Color3.new(1, 0, 0)
	newhitbox.Size = Vector3.new(4.2, 5, 6.69)
	newhitbox.Parent = character

	local weldConstraint = Instance.new("WeldConstraint")
	weldConstraint.Part0 = newhitbox
	weldConstraint.Part1 = character.HumanoidRootPart
	weldConstraint.Parent = newhitbox
	
	task.delay(2, function()
		newhitbox:Destroy()
	end)
	
	newhitbox.Touched:Connect(function()
		print("touched")
	end)
end

That didn’t really solve my problem, as it doesn’t fix the fact that the box that should detect any touching humanoid doesnt do that unless it has mass, which is a problem as the player twitches everytime and freezes whenever it is called. The part itself is staying on the proper place.

Better to just use Debris, as far as I’m concerned.

I thought it would, because in the original one, you connect the .Touched function after you destroyed the part, which wouldn’t work.

I’m using task.delay because afaik Debris still uses the default wait(n) instead of task.wait(n).

After reading that i tried making the touched function a regular function and call it whenever the hitbox is touched, while the box duration and spawn time is different (lasts 1 second, spawns every 0.5 second) its registering the touch, but with the spawn rate like that, its registering way too often and results in massive damage. How can i maybe add a delay to the hitbox?

while attack do
	function hitbarrage(hit)
	print(hit.Name.."touched")
		if hit and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(1)
		end
	end

		character.Humanoid.WalkSpeed = 3
		wait()

local newhitbox = Instance.new("Part")
newhitbox.Name = "hitbox"
newhitbox.CFrame = character.HumanoidRootPart.CFrame
newhitbox.Anchored = false
newhitbox.CanTouch = true
newhitbox.CanCollide = false
newhitbox.Transparency = 0.55
newhitbox.Massless = true
newhitbox.Color = Color3.new(1, 0, 0)
newhitbox.Size = Vector3.new(4.2, 5, 6.69)
newhitbox.Parent = character

local w = Instance.new("Weld",newhitbox)
w.Part0 = newhitbox
w.Part1 = character.HumanoidRootPart
w.C1 = CFrame.new(0,0,-2.89)

game.Debris:AddItem(newhitbox,1)
wait(0.5)
newhitbox.Touched:Connect(hitbarrage)
									
end	

You can try to add a debounce.

Try this:

local damageCooldown = 0.5

while attack do
	character.Humanoid.WalkSpeed = 3
	task.wait()

	local newhitbox = Instance.new("Part")
	newhitbox.Name = "hitbox"
	newhitbox.CFrame = character.HumanoidRootPart.CFrame
	newhitbox.Anchored = false
	newhitbox.CanTouch = true
	newhitbox.CanCollide = false
	newhitbox.Transparency = 0.55
	newhitbox.Massless = true
	newhitbox.Color = Color3.new(1, 0, 0)
	newhitbox.Size = Vector3.new(4.2, 5, 6.69)
	newhitbox.Parent = character

	local w = Instance.new("WeldConstraint")
	w.Part0 = newhitbox
	w.Part1 = character.HumanoidRootPart
	w.C1 = CFrame.new(0,0,-2.89)
	w.Parent = newhitbox
	
	task.delay(1, function()
		if newhitbox:IsDescendantOf(workspace) then
			newhitbox:Destroy()
		end
	end)
	
	task.wait(0.5)
	
	local humanoidDebounce = {}
	
	newhitbox.Touched:Connect(function(hit)
		local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
		
		if Humanoid and not humanoidDebounce[Humanoid] then
			humanoidDebounce[Humanoid] = true
				
			Humanoid:TakeDamage(1)
			
			task.wait(damageCooldown)
			humanoidDebounce[Humanoid] = nil
		end
	end)
end	

Change the cooldown time to your liking.

Seems to be working as intended with this, thanks for the help.