How to find and print everything in an area

Hi, I’m using ZonePlus. I want/need to know how to print (for example) all “BaseParts” within a region/zone once a player enters it. Thank you in advance for any help.

2 Likes

I believe you can

I came up with this:

Create a Server Script and Put it in ServerScriptService

local Part = "BIGPART"
function DetectParts (hit)
	local H = hit.Parent
	if H then
		print(H)
	end
end
for _,i in pairs(workspace:GetChildren()) do
	if i.Name == Part then
	i.Touched:Connect(DetectParts)
		
	break
	end
end

Works.
if you are looking for Player BaseParts. this may be the script for you

2 Likes

Thanks , but it’s not Player BaseParts I’m looking for. It’s environment BaseParts I’m looking for.

1 Like

you might be able to tweak the function to look for BaseParts

1 Like

I modified the script. it now detects the Instances, and their children, however there is a delay

Enabled = false
function t(hit)
	local J = hit.Parent:GetChildren()
	local H = hit.Parent
	if J then
		Enabled = true
	
	if H and not not Enabled then
			print(H,J)
		end
	end
end	
function d()
	Enabled = false
end
for _,i in pairs(workspace:GetChildren()) do
	if i.Name == "BIGPART" then
		i.Touched:Connect(t)
		i.TouchEnded:Connect(d)
	end
end
1 Like

It’s a cheap and unoptimised solution, but why not create a large invisible part around your zone?

That way, you could call instance:GetTouchingParts() whenever the player moves into the zone:

local function main(hit : Part)

    -- Checks whether it's a player that entered the zone
    if not hit.Parent and not hit.Parent:FindFirstChildOfClass("Humanoid") then return end

    -- Iterates through the parts physically touching the zone part in the Workspace
    for k, v : BasePart in pairs(zonePart:GetTouchingParts()) do
        print(k, v)
        -- your code here
    end
end

-- Only trigger when the zone part is touched
zonePart.Touched:Connect(main)

Hope this helps.

1 Like

This sounds promising. Thanks. I’ll give it a try.

1 Like

I’m still not getting the desired result. Zoneplus doesn’t utilise “Touched” events to detect a player entering, or parts within it. It works more like “Region3.new” which I think has maybe become replaced by something new. AlvinBlox did a video which points to what I am trying to achieve. ZonePlus is a module that works in what I presume is a very similar way. Here’s a screenshot of the AlvinBlox script/code.

1 Like

If your read the api documentation on zoneplus,
there’s a method called Zone:getParts() on a zone made from Zoneplus.new() which returns all baseparts within bounds of the zone.

1 Like

I see what you’re trying to do now.

In which case, why not combine both ideas?

  • Create a Region3 instance between two vectors
  • Create a part with a volume and position identical to the region
  • When that part is touched, use WorldRoot:FindPartsInRegion3() to return a table of instances

Would that be a feasible solution?

1 Like

ZonePlus the module is made specifically for zone based functionality, because it uses the far more accurate spatial query functions over region3. And it’s the module OP stated they were using.

1 Like