GetPartsInPart dosen't return the correct objects

I’m making a script that keeps an hitbox on the soap bar and it has this to keep running and as soon as it hits any player part aslong as they aren’t alredy ragdolled they ragdoll them, but I don’t know why it starts working for 2 seconds then suddenly only detects the baseplate or just dosent detect the legs

local d = false
	while task.wait() do
		local hits = workspace:GetPartsInPart(script.Parent.Hitbox)
		for i,hit in hits do
			if d then continue end
			d = true
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent.Humanoid.Health <= 0 then continue end
				print("A")
				if hit.Parent:GetAttribute("Ragdoll") then continue end
				print("hit")
				task.spawn(function()
					hit.Parent:SetAttribute("Ragdoll",true)
				end)
				hit.Parent.HumanoidRootPart:ApplyImpulse((hit.Parent.HumanoidRootPart.CFrame.LookVector+Vector3.new(0,0.2,0)*power))
			end
			d = false
		end
	end

here:

This could be because you are never setting the ragdoll attribute back to false

the ragdoll atribute is to tell another script to ragdoll the player but as you can see i make it print out any hit whos parent has an humanoid and it prints nothing when the soap hits the legs

Pretty sure the GetPartsInPart method needs a Part to be fully inside, try using this instead:

local hits = script.Parent.Hitbox:GetTouchingParts()

Still nothing… and with that it dosent work at all

What does the hitbox look like?

its that red part taht follows the pink block aka the soap bar

Is the hitbox anchored and being repositioned or is it an unanchored Part that’s welded to the soap

I would recommend positioning the hitbox once and welding it to the soap, then unanchoring it so it can perform physics calculations by itself without needing a moving part

unanchored and being repositioned every task.wait()

That can also cause problems since the part wont actually have time to move by itself

Thats what i started with but idk why the hitbox just flew away

Use a WeldConstraint, set the hitbox position to the soap, set the part0 to the hitbox, part1 to the soap, unanchor the hitbox, set the hitbox to massless

Hitbox just falls off like it isn’t welded

local new = soap:Clone()
	local hit = game.ServerStorage.Hitbox:Clone()
	local weld = Instance.new("WeldConstraint")
	hit.Parent = new
	new.Parent = workspace
	new.Position = noozle.Attachment.WorldPosition
	new.Anchored = false
	hit.CFrame = new.CFrame
	weld.Parent = new
	weld.Part0 = hit
	weld.Part1 = soap
	hit.Anchored = false
	new:ApplyImpulse(Vector3.new(0,10,-20))
	new.Script.Enabled = true

The only reason that would be is if the weldconstraint isnt parented right or has its Part1 or Part0 set wrong, try running the script and track the WeldConstraint to make sure

Also if this is the only time you actually need to use this soap you could already have the Hitbox and weldconstraint set up inside the data model, without using script to create everything afterwards

I mean its used as a projectile so

Parent the weld to the hitbox, not the soap (not sure if this would even change anything but since you made the hitbox the Part0 it might)

The code is a bit messy, but I believe it’s because you continue if Health is <= 0 or the attribute Ragdoll is true, which results in d never getting set back to false, and the loop constantly skipping the rest of the code.

I would also suggest using BasePart.Touched events rather than constantly performing expensive spatial queries.

If you need help cleaning up the code, I can help with that too.

This post was about me recommending return instead of continue but that will also end the whole function, you’ll have to use the debounce with an if-statement in the for loop

Edit: That may very well count for all the other uses of continue too in this case since continue ends a for loop completely im pretty sure