game.Workspace:GetPartsInPart(Part) not working

Hi guys! I have a script that randomly rolls a number 1-5 and and it does an action based on that number. when the number is chosen it fires an event to execute an action. But for one of the actions, I used GetPartsInPart to see if a humanoid is in a box, and if they are, they die. However sometimes it doesnt kill all of the humanoids in the part, despise them being in there.

and here is the code:

if rng == 5 then
		

		local parts = game.Workspace:GetPartsInPart(hitbox)



		for i, part in pairs(parts) do
			if part.Parent:IsA("Model") then
				
				if part.Parent:FindFirstChild("HumanoidRootPart") and part.Parent.Name ~= script.Parent:FindFirstChildWhichIsA("IntValue").Name then
					local player = game.Players:FindFirstChild(hitbox:FindFirstChildWhichIsA("IntValue").Name)
					local tagval = part.Parent:FindFirstChildWhichIsA("IntValue")
					tagval.Name = player.Name
					print(part.Name)
					part.Parent:FindFirstChild("Humanoid").Health = 0

				end
			end



		end







	end

Try adding prints to debug the code between the if checks

1 Like

You should use :GetPartBoundsInBox(), its more reliable for what your trying to do, as combat systems usually use this method for detection.

I also suggest checking for Humanoids rather than HumanoidRootParts, but up to you.

2 Likes

thank you so much, this helped a lot and i amrked it as solution

1 Like

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