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

Is it possible to make .itemEntered/.itemExited fire on every part that enters the zone?
I can’t just use the .partEntered/.partExited events because the parts that I am looking for are achored parts that have a Light (any PointLight/SurfaceLight/SpotLight), and I can’t think of a way to reliably add tracking to every part I need.

Edit, some more info:
I’m trying to make road signs glow when you drive close them, currently each sign that is tagged with “retroreflectiveSign” will get a new zone, and in that zone I want to detect each part that enters and check if that part has lights.

for _,o in pairs(CLS:GetTagged('retroreflectiveSign')) do
	local newZone = ZONE.fromRegion(o.CFrame, Vector3.new(300,300,256))
	-- zone size is mainly for testing, will make a better one later
	
	local coro = nil
	
	newZone.itemEntered:Connect(function(part)
		print('part entered')
		local pol = part:FindFirstChildOfClass('PointLight')
		local sul = part:FindFirstChildOfClass('SurfaceLight')
		local spl = part:FindFirstChildOfClass('SpotLight')
		if part and (pol or sul or spl) then
			print('is light')
			coro = coroutine.create(TrackLight)
			coroutine.resume(coro, o, part, pol, sul, spl)
		end
	end)

	newZone.itemExited:Connect(function(part)
		print('part exited')
		local pol = part:FindFirstChildOfClass('PointLight')
		local sul = part:FindFirstChildOfClass('SurfaceLight')
		local spl = part:FindFirstChildOfClass('SpotLight')
		if part and (pol or sul or spl) then
			print('was light')
			coro.yield()
		end
	end)
end

Do not use this module. A game I recently released depends on this heavily but it ended up breaking. The code is messy and does not account for errors. I had to fix many issues with it like players not being registered or detected. The regions sometimes failing to calculate causing the zone to break. I suggest to make your own using robloxs new blockcast/shapecast.

:trackItem should help you out here:

If you’re experiencing issues you’re welcome to share reproduction steps - even better submit modifications through Pull Requests via GitHub. This wrapper is actively used throughout many games which haven’t reported issues with player registration.

1 Like

I know about :trackItem, I’m asking if there’s a way to simply track every item that exists in the workspace. There no good way for me to start tracking what I need to detect because the models that the lights are connected to are constantly being spawned/despawned.

ZonePlus purposely doesn’t track all workspace objects (or provide a way) because this could become expensive for games with lots of instances.

Are you able to use CollectionService to tag all parts that have lights? You could then listen for when a part with lights is added to workspace then track it for all relevant zones.

I could explore making :trackPartsWithTag() a futute update to help with this.

Any plan for new update or maybe rewrite?

2 Likes

I find this to be a misconstrued statement. I’ve been using it since it’s came out and only had a few issues, which Ben fixed almost instantly (can check my posts on this thread for proof). I believe you’re just having user error with bad code.

3 Likes

I’d definitely like to introduce support for shapecasts but right now I’m too occupied with other projects and zoneplus is in a nice enough place to not need any immediate updating.

2 Likes

Or maybe you wanna make it like TopbarPlus? Suddenly out of nowhere there’s an update to V3.

I believe the only reason TopbarPlus needed an update was to match the theme of Roblox’s new (terrible imo) “experience controls.” But yeah, an update to ZonePlus would be great.

2 Likes

Ive tested it hundreds of times in live servers with my alt and friends and never saw an issue with it so I thought it was working. But after seeing it stress tested when I released my game it started to fail like zoneRegion being nil even when I call the _update() method manually. I also never destroy the zones at least for the server which is what I use it mainly for. I did disconnect and reconnect events for performance. All my zone containers/parts are regular squares/blocks. Not sure what caused this issue. I tried fixing it but just ended up creating my own module.

All this, user error. You’re not specifying the code for how you made the regions, you’re disconnecting and re-connecting events which isn’t the fault of the module but user error.

3 Likes

This is the bug I was also getting. Its the zoneRegion failing to calculate under the _update() method. Module does not account for errors, make your own.

Another example. No account for errors

I don’t know if I should use this or make a smaller version.

I’m not entirely sure if this was answered already so soz if so :sad:
I noticed that creating a new zone container in-place of a previously deleted zone would make it unusable, here’s an example

I’m basically using zoneplus in tandem with a map loading system so any help would be appreciated :smile: :+1:

Edit: Here’s a repro place
ReproPlace.rbxl (92.6 KB)

Edit 2: Here’s another repro place this one has strangely inconsistent behaviour
ReproPlace2.rbxl (93.8 KB)

Thanks for the report will look into it :+1:

2 Likes

I am having problems with the following code:

zone.PlayerExited:Connect(function(player)
local players = zone.getPlayers()
if #players == 0 then
// perform task
end
end)

For some reason, on the event that there are 0 players, the above code does not perform the task in some cases. I’m not sure what case is causing it. Either a player that dies while in zone, or perhaps someone disconnecting while in the zone.

Any ideas?

You shouldn’t call method “getPlayers()” with . because it passes first argument as self or nil if not arguments were given; so call it with : instead because it automatically passes self

Right, nice catch.

I believe this was just a typo in the forum post. However, I will try again and make sure that a colon is used instead of a period. If I still run into issues, I’ll report back.