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

Found an issue when you try to disconnect and connect the localPlayerEntered listener. When connecting, some part of the initialization is faulty as it errors within it’s update loop (I think). I don’t think has anything to do with my specific implementation as I’ve not altered the module at all.

Lines it errors in (line 264):

Good spot, turns out there was a missing line which was preventing local events from completely disconnecting. This should be fixed now:

Great! Thanks again for fixing them so fast, great module!

1 Like

Heyo, seem to have a slight issue that I’m not sure how to handle.
In the green zone, the lighting is supposed to be bright, and in the blue dark, however it seems that if the player leaves and re-enters quickly they can supersede the blackout and avoid the dark. Any help?

Can you print ‘entered’ and ‘exited’ and the very top within your entered/exited events then share the same video.

If these print correctly then it may be something to do with how you’re tweening the lighting as apposed to the zone methods themselves.


Hopefully this helps a little, I’ve tried setting the detection to Precise but it wouldn’t allow me to.

What’s happening for you is the following:

This is caused by the exiting properties of one zone being applied after the entering properties of the other (due to the ability to be in more than one zone at once).

local Zone = require(game:GetService("ReplicatedStorage").Zone)
local lightingAreas = workspace.LightingAreas
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local DEFAULT_VALUES = {
	FogColor = lighting.FogColor,
	FogStart = lighting.FogStart,
	FogEnd = lighting.FogEnd,
	ClockTime = lighting.ClockTime,
}

local function changeLighting(lightingDictionary)
	tweenService:Create(lighting, TweenInfo.new(0.5), lightingDictionary):Play()
end

for _, group in pairs(lightingAreas:GetChildren()) do
	local zone = Zone.new(group)
	zone.lightingDictionary = {
		FogColor = group.Color,
		FogStart = 20,
		FogEnd = 200,
		ClockTime = 0,
	}
	zone.localPlayerEntered:Connect(function()
		changeLighting(zone.lightingDictionary)
	end)
	zone.localPlayerExited:Connect(function()
		changeLighting(DEFAULT_VALUES)
	end)
end

The desired outcome is the following:

This is achieved by tracking how many zones we are in, then when the exited signal is fired for a zone, we first check if we are currently in any other zones. If we are, then apply that zones properties, else only then reset to default.

local Zone = require(game:GetService("ReplicatedStorage").Zone)
local lightingAreas = workspace.LightingAreas
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local DEFAULT_VALUES = {
	FogColor = lighting.FogColor,
	FogStart = lighting.FogStart,
	FogEnd = lighting.FogEnd,
	ClockTime = lighting.ClockTime,
}

local zonesWithin = {}
local zonesWithinCount = 0
local function changeLighting(lightingDictionary)
	tweenService:Create(lighting, TweenInfo.new(0.5), lightingDictionary):Play()
end

for _, group in pairs(lightingAreas:GetChildren()) do
	local zone = Zone.new(group)
	zone:setDetection("Centre")
	zone.lightingDictionary = {
		FogColor = group.Color,
		FogStart = 20,
		FogEnd = 200,
		ClockTime = 0,
	}
	zone.localPlayerEntered:Connect(function()
		zonesWithin[zone] = true
		zonesWithinCount += 1
		changeLighting(zone.lightingDictionary)
	end)
	zone.localPlayerExited:Connect(function()
		zonesWithin[zone] = nil
		zonesWithinCount -= 1
		if zonesWithinCount == 0 then
			changeLighting(DEFAULT_VALUES)
		else
			for zone, _ in pairs(zonesWithin) do
				changeLighting(zone.lightingDictionary)
				break
			end
		end
	end)
end

We also set the zones detection to ‘Centre’ for the latter example which is more desirable for your situation:

zone:setDetection("Centre")

You can find these examples at the playground within StarterPlayerScripts:

https://www.roblox.com/games/6166477769/ZonePlus-Playground

6 Likes

Yo! for some reason beyond my understanding, Zone+ v2 is firing its events once PER PLAYER in the server!

So if a player enters a zone, it will fire the event as many times as there are players in the server, is this supposed to be how it works?

Might this have something to do with the new client side checking? I really don’t want this feature, anyone know whats going on?

This isn’t something I can reproduce:

How are you setting up your zones? Can you provide your zone code?

1 Like

yeah I’m going to DM you a pastebin.

EDIT:

Wow as Iwas sending you a pastebin of my code, I realized i was connecting the event each ttime a player joined with the PlayerAdded event. OOF!

this module is amazing once again! When my game makes some money i want to buy you a car.

2 Likes

Is there a way to donate?
Cause this is awesome and I noticed the model is free.
I’d love to make a donation to this amazing resource!
Thanks so much this is probably the most helpful resource I’ve found in a while!

Appreciate it! I don’t take any donations although sharing resources like ZonePlus with people who may benefit from it and helping where you can is more than enough.

1 Like

Alright! Thanks for the amazing resources :smiley:

For those interested in switching to the Deferred Signal Behaviour who use ZonePlus we’ve just released an update to make it compatible:

3 Likes

Thank you so MUCH!
I’ve been struggling with zones for some time now, and you always get the solution done.

With this module I can now finally create SafeZones for people in my new game :slightly_smiling_face:

I appreciate your work for this community!

1 Like

Does credits work instead of the thread link?
Roblox doesn’t allow me to link your thread in my description.

-NH

Sure that’s absolutely fine. .

1 Like

Having an issue around legacy tools that still use mouse.Target and mouse.Hit touching on the edges of the Zone. I’ve fixed the majority of what I can with raytracing and ignoring zone parts.

Is there any plans to support not requiring zone parts inside of workspace?
I believe it possibly wouldn’t be feasible because of the use of Touched events etc.

I believe you can just make the parts in a new collision group, and make this group not collide with the default collision group.

This should prevent the default raycasting what mouse.Hit uses from colliding.

1 Like

I have 2 questions, since I am on mobile and I cannot test. If I move the Player’s character with CFrame, while this is in a zone, would the effects of the zone still happen, or they will de-activate?
And if I want to change what should trigger the event, how would that be? Because I want a simple part when entered to trigger the event, not a Player’s character.


Also great resource, I love it!!!