How to get all parts touching my range part

i want to check if parts are inside the hitbox for my detector, the table returns nil.

I found out why: my part has cancollide off, and the function “GetTouchingParts” only works with it on.

What can i do to fix this? i cant find out how to set up a touch intrest either, when i try to clone one into the part it deletes itself

A TouchInterest is created when you connect a function to the touched event of the part. So if I remember correctly you could do this:

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

However, you could also use the newer GetPartsInPart. It has parameters for finetuning its behavior.

i forgot to mention, “getpartsinart” just gives me an error saying its not a valid child, i saw on the documentation it tells me to use it, but it justs breaks the script

GetPartsInPart is a method of WorldRoot which WorkSpace inherits from. BaseParts don’t inherit from WorldRoot. So if you tried to index the part with GetPartsInPart, do this instead:

local partsInPart = workspace:GetPartsInPart(part)

You can also optionally give OverlapParams.

oh ok, ig i should have done more researc in that… thanks!

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