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.
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
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
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