GetTouchingParts() not working when CanCollide is off?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local zombieFlingEvent = ReplicatedStorage:WaitForChild("ZombieFlingEvent")

zombieFlingEvent.OnServerEvent:Connect(function(player)
	print("Received event")

	local character = player.Character
	if not character then return end

	local swordHitbox = character:FindFirstChild("SwordHitbox")
	if not swordHitbox or not swordHitbox:IsA("Part") then
		print("SwordHitbox not found!")
		return
	end

	swordHitbox.CanCollide = false
	swordHitbox.CanTouch = true

	for _, touchingPart in ipairs(swordHitbox:GetTouchingParts()) do
		print("Checking touching parts...")
		local parentModel = touchingPart:FindFirstAncestorOfClass("Model")
		if parentModel and parentModel:FindFirstChild("Humanoid") and parentModel.Name == "Zombie" then

			local rootPart = parentModel:FindFirstChild("HumanoidRootPart")
			if rootPart then
				rootPart.AssemblyLinearVelocity = rootPart.AssemblyLinearVelocity + Vector3.new(0, 50, 0)
				print("Zombie flung!")
			end
		end
	end
end)

CanCollide on
image

CanCollide off
image

Thats just what happens, theres no way to avoid it really.

I would try to use collision groups, if that doesn’t work, im not sure what else might.

It’s weird though, because it SHOULD since CanTouch is enabled, right?

I mean, if it can’t collide with anything, it wont detect collisions in scripts.

It probably should tho.

I coulda sworn that CanTouch still works when CanCollide is off what

If your talking about .Touched events, those do work with can collide off, idk why…

Yeah it does (In a script I made to test I wrote a function and forgot to check the event :skull:)

If it works with .Touched, why would it not work with GetTouchingParts()??

im not sure, its weird ig…

Try out collision groups, otherwise you will probably have to improvise with something idk.

I mean, the API does say :GetTouchingParts() will return a table of all BasePart.CanCollide true parts that intersect with it so this is intentional.

However, I found that there is a workaround to this: if you have an empty .Touched event and disconnect it after, it will return the touching parts.

This is because of (I believe) something to do with the .Touched event interfering with the parts’ physics, making it behave differently and being prone to collision.


local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	
	connection:Disconnect()
	return results
end

local touchingParts = GetTouchingParts(workspace.TestPart1)
print(touchingParts) --> Table with the touching parts

Maybe just use workspace:GetPartsInPart()?

CanCollide is a very weird property

I have no idea why this isn’t working,

It’s weird. You have to put a touched event somewhere before you ask for the get touching parts.

Part:GetTouchingParts() -- {}
Part.Touched:Connect(function()
End)

Part:GetTouchingParts() -- returns touching parts

I’m pretty sure it’s a bug.

Really??

Use workspace:GetPartsInPart. It’s the newer version to this and should work better

Using a bug to solve an issue is a really bad practice, since the bug will be patched.