:GetPartsInPart suddenly not returning anything

I’m using a hitbox system that uses :GetPartsInPart, but for whatever reason it isn’t returning anything.
Here’s the function I use:

function hitboxModule:CheckAttack()
	print("Check atk request received")
	print(self.Reference) --Note this
	local returned = {}
	local overlap = OverlapParams.new()
	overlap.FilterType = Enum.RaycastFilterType.Exclude
	overlap.FilterDescendantsInstances = {self.Reference.Parent}
	local getPartsIn = game.Workspace:GetPartsInPart(self.Reference, overlap)
	print(#getPartsIn) --Note this too
	for _, part in ipairs(getPartsIn) do
		print(part.Name)
		if part.Name == "HumanoidRootPart" then
			print(part:FindFirstAncestorWhichIsA("Model").Name)
			if part:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then
				print("yessir i found one")
				print(part:FindFirstAncestorWhichIsA("Model").Name)
				if table.find(returned, part) then
					print("Already in table")
					continue
				end
				table.insert(returned, part)
			end
		end
	end
	return returned
end

What the first line I want you to note prints Hitbox while the other prints 0

Hitbox --This is a real BasePart created right before hitbox checks
0

The only reason this might be happening is because I changed the code so the hitbox is created right before the checks instead of following the player all the time, though that shouldn’t be the case.
I tested this out on both an NPC and real players, and there aren’t any errors other than

Property "Animator.EvaluationThrottled" is not currently enabled. (x7)
1 Like

Ran some tests, it had nothing to do with when the hitbox was made relative to the :GetPartsInPart check or the OverlapParams
This is a really frustrating roadblock in the game so any help would be much appreciated!

1 Like

Try using GetPartsInBounds instead?

2 Likes

Tried that (btw it’s GetPartBoundsInBox) but it still didn’t work

1 Like

Check the Collision Group
(characters!!!)

1 Like

the only collision group is default
this stopped working right after i made changes to make the hitbox right before checking inside of it, though i don’t understand how that’s a problem

1 Like

updated version of your script with additional checks and a brief delay to ensure the hitbox is registered:

local hitboxModule = {}

function hitboxModule:CheckAttack()
	print("Check atk request received")
	print(self.Reference) -- Note this

	-- Ensure the hitbox is positioned correctly
	print("Hitbox Position:", self.Reference.Position)
	print("Hitbox Size:", self.Reference.Size)

	-- Brief delay to ensure the physics engine updates
	wait(0.1)

	local returned = {}
	local overlap = OverlapParams.new()
	overlap.FilterType = Enum.RaycastFilterType.Exclude
	overlap.FilterDescendantsInstances = {self.Reference.Parent}

	-- Get parts in the hitbox area
	local getPartsIn = game.Workspace:GetPartsInPart(self.Reference, overlap)
	print("Number of parts found:", #getPartsIn) -- Note this too

	for _, part in ipairs(getPartsIn) do
		print("Found part:", part.Name)
		if part.Name == "HumanoidRootPart" then
			local model = part:FindFirstAncestorWhichIsA("Model")
			if model and model:FindFirstChild("Humanoid") then
				print("Humanoid found in model:", model.Name)
				if not table.find(returned, part) then
					table.insert(returned, part)
				else
					print("Already in table")
				end
			end
		end
	end
	return returned
end

return hitboxModule

Example of Creating the Hitbox

If you are creating the hitbox right before the check, ensure it is properly parented and positioned:

local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(5, 5, 5)
hitbox.Position = player.Character.HumanoidRootPart.Position -- Example position
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.Transparency = 1
hitbox.Parent = workspace

hitboxModule.Reference = hitbox
2 Likes

I set the transparency of the hitbox to 0.5 so I know that the hitbox is where it should be

tried that earlier, even used task.wait(3), still nothing

Don’t worry, I’ve already done that in a separate script

1 Like

Did some more testing, and for WHATEVER reason it only worked when the hitbox was parented to the player’s character model.
That was a huge waste of 2 hours
Thank yall for taking the time to read this and help me though, really appreciate your time

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.