ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries

Hey! Thanks for making this module, it’s really neat :smile:

However, I’m having an issue when using a DragDetector
Basically, my zone seems to not ‘‘Detect’’ a part when I use DragDetector to drag the part inside the zone

Heres a video of what I mean:

My Code (ServerScript):

local Zone = require(game:GetService('ReplicatedStorage').Zone)
local Container = workspace:WaitForChild('Deposit')

local zone = Zone.new(Container)

zone.partEntered:Connect(function(part)
	print(part.Name)
	
end)

zone.partExited:Connect(function(part)
	print(part.Name)
	
end)

Thanks!

It would be great if this handled for when players die within a zone. Currently, it never triggers the exited event.

(and it looks like there’s a memory leak regarding this as stated a few posts above)

3 Likes

Hello there, I am having a problem with getting touching zones of a player. I have a localscript with these 2 lines of code:

local ZoneController = require(game:GetService("ReplicatedStorage").Zone.ZoneController)
local touchingZonesArray, touchingPartsDictionary = ZoneController.getTouchingZones(game.Players.LocalPlayer)
print(touchingZonesArray, touchingPartsDictionary)

However, this returns an empty array and a nil value, and I have no idea why. I also tried to modify it a bit and run it as a command in the command bar, but it also gave the same empty and nil values. Could someone help me with this?

You’re not doing it correctly.

I suspected that. How am I meant to do it?

Nvm I think I found the issue. I changed it to

local ZoneController = require(game:GetService("ReplicatedStorage").Zone.ZoneController)
local touchingZonesArray, touchingPartsDictionary = ZoneController.getTouchingZones(game.Players.LocalPlayer.Character.HumanoidRootPart)
print(touchingZonesArray, touchingPartsDictionary)

and now its working as expected.

What confuses me is that in the documentation it seems as it takes the player as an input, and not the humanoidrootpart. I had to go look in the ZoneController modulescript itself to find the fix.


Hopefully this helps some poor soul that has the same issue and finds this comment!

2 Likes

I have zones which are cloned from ServerStorage with scripts inside which initiate the zones. This script works the first time it is cloned, but for some reason won’t work after. It would be too messy to do this with the rotation (which I’ve tested, and the zones work like that) as the rotation is for maps and is too general, which is why I have scripts inside those maps.

“Why do you have 24 event listeners” is the real question here

This is a great module, but sometimes for some reason all the zones just break upon test playing. I don’t see any errors in the output as well, the enter/leave detection just doesnt work for zones. What might be causing it?

Need to clarify more of what the issue is along with code shown.

Need more information, just based off what you’re saying alone is user error 99%.

How’s this not clear?

local Zone = ZonePlus.new(script.Parent.Part)
Zone.playerEntered:Connect(function(plr)
--code
end)

it looks something like that, a script in a part being cloned, works the first time, script runs the second time but zone doesn’t work.

1 Like

This script won’t work for map rotation:

local part = game:GetService("ServerStorage").Part
local scriptOg = true

local p

while true do
	scriptOg = not scriptOg
	local p2 = part:Clone()
	if p then 
		--task.delay(0, function() 
			p:Destroy() 
		--end)
	end
	p = p2 
	p.Enabled = true
	
	p.Parent = workspace
	
	task.wait(10)
end

but this script will:

local part = game:GetService("ServerStorage").Part
local scriptOg = true

local p

while true do
	scriptOg = not scriptOg
	local p2 = part:Clone()
	if p then 
		task.delay(0, function() 
			p:Destroy() 
		end)
	end
	p = p2 
	p.Enabled = true
	
	p.Parent = workspace
	
	task.wait(10)
end

script inside the part:

require(game:GetService("ServerStorage").Zone).new(script.Parent).playerEntered:Connect(function(plr)
	print(plr)
end)

Why are you putting the script in the map and not handling it outside? Are you making the container, on the same map, multiple times?

That’s not the best way of handling multiple zones.

Like I said in the original post, the map rotation is a pretty general script, it’d be pretty silly to have so many if statements checking for the name of the map and if it matched up. I could also alternatively have a module script inside which is required (like a “package” of sorts) but I doubt that would solve the issue.

I think this is the best way of making the container, I’m not making it on the same map as the map is destroyed after it’s use (it’s clone, at least)

Figured out why task.delay works. It was delaying it to after p was set to p2 so it deleted the new one and kept the old. Still don’t know how to make a new zone in a disabled script in map cloned.

Yeah I probably had to clarify more.

so basically, I have a tycoon game where I use zones to detect door and garage enters/leaves. (& more)

I have set up everything right and it worked most of the time, only sometimes upon playing the game all zones in the game start to break and for some reason my audios linked to sound groups also get affected by this (they just unlink), I’m not sure how it’s relevant.

I can show you some code but like I said, all zones sometimes work or sometimes none do. I have removed the onEnter(Player) functions and typically put in print statements to detect Enters and Leaves but that leaves me with no outputs, I also use zones for region detections from different scripts and they also do not seem to work when the zones break. It’s all or nothing.

Now I am wondering, is there a cap on how many zones you can use?

self.Zone = ZoneModule.fromRegion(self.Model:FindFirstChildWhichIsA('Attachment', true).WorldCFrame, Vector3.new(15, 15, 15))

self.Zone.playerEntered:Connect(function(Player) onEnter(Player) end)
self.Zone.playerExited:Connect(function(Player) onLeave(Player) end)

(Keep in mind that I’m receiving no errors/warnings from the zone script)

Got it working, had some problems with my metatables, sorry!

Anyway to get around :setaccuracy() changing the accuracy of all zones. This is very annoying and doesn’t allow us to have different zones with different accuracy. I’m guessing I’d have to rewrite the _formHeartbeat function in zonecontroller to make a heartbeat connection for each zone, but I don’t know how performant that would be