GetTouchingParts() not working?

				local TouchingParts = Circle.TouchPart:GetTouchingParts()
				
				for i,v in pairs(TouchingParts) do
					print(v)
					local Humanoid = v.Parent:FindFirstChild("Humanoid")

					if Humanoid then
						print(Humanoid.Parent)
						
					end
				end

As the title says, trying to detect in pairs, but it doesn’t print v or the humanoid.

2 Likes

Use .Touched instead of GetTouchingParts.

GetTouchingParts() does not consider parts with cancollide disabled and does nothing if the part itself has cancollide disabled
to use the part’s CanQuery property instead try this:

local TouchingParts = workspace:GetPartsInPart(Circle.TouchPart)
for i,v in TouchingParts do
	print(v)
	local Humanoid = v.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		print(Humanoid.Parent) --if you only want to detect one humanoid insert a break after this line
	end
end
2 Likes

Can’t. .Touched is buggy for the specific case I’m using this, need it for an “AoE” type thing.

This works, but how do I detect when a player leaves?

1 Like

I don’t know how to indent code on mobile so this might look like crap but here’s a possible solution (I can’t test this right now so bear with me)

local inArea = {}

local TouchingParts = workspace:GetPartsInPart(Circle.TouchPart)
for i,v in TouchingParts do
	print(v)
	local Humanoid = v.Parent:FindFirstChild("Humanoid")
	if Humanoid and not table.find(inArea, v.Parent) then
		print(Humanoid.Parent)
		table.insert(inArea, v.Parent)
	end
end

for i,v in inArea do
	if not table.find(TouchingParts, v) then
		table.remove(inArea, i)
		--your code here
	end
end

Nope, doesn’t detect anything in the if Humanoid and not table.find(inArea, v.Parent) then statement.

finally got around to it, this should work:

local TouchingParts = workspace:GetPartsInPart(Circle.TouchPart)
local inArea = {}

for i,v in TouchingParts do
	local rootPart = v.Parent:FindFirstChild('HumanoidRootPart')
	local humanoid = v.Parent:FindFirstChildOfClass('Humanoid')
	if rootPart and table.find(TouchingParts, rootPart) and not table.find(inArea, humanoid) then
		table.insert(inArea, humanoid)
		print(string.format('added %s\'s humanoid', rootPart.Parent.Name))
		break
	end
end

for i,v in inArea do
	local toCheck = v.Parent:FindFirstChild('HumanoidRootPart')
	if toCheck and not table.find(TouchingParts, toCheck) then
		table.remove(inArea, i)
		print(string.format('removed %s\'s humanoid', v.Parent.Name))
		--your code here
	end
end

Sorry for the late response, but it doesn’t print when you leave the circle.

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