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

You can set a name property to achieve this or user zone.groupParts, explained in more detail here:

In short, if your zone contains multiple parts and you want to retrieve an individual parts name from that zone when you enter it, you should instead split these parts up into their own zones each, then set a name or instance property for each and check for this.

There’s no change to performance when you split up zones so this is the best solution. For example, 1000 zones of total volume 500 studs squared is equivalent in performance to 1 zone of volume 500 studs squared (for the player events at least).

1 Like

Is it possible to do zone.new() without using parts, maybe create a zone using positions?

Not for v2 since most of the Region3 checks are casted over characters which then check for zone parts - this requires these parts to remain in workspace. You can learn more about the methodology here:

1 Like

Hey, I’ve been having issues with your module, 10% of the time it would work and the rest of the time it wouldn’t, I don’t know if it’s a problem with my code but it seemed to work with the touched event prior, so perhaps we may talk somewhere to fix this? that’d be great.

Im pretty confused how to use this. What to do with the Zone module script? What do i need to do to make a Ambience Zone?

It’s recommended you place the Zone module in ReplicatedStorage. After that, create parts to engulf and represent your zone, group these together, then require this (a model, folder, or even a single basepart) within the constructor (as the zoneGroup):

-- Assuming we place ZonePlus in ReplicatedStorage
local Zone = require(game:GetService("ReplicatedStorage").Zone)
local zoneGroup = workspace.SafeZoneGroup
local zone = Zone.new(zoneGroup)

You can then listen for events, such as a player entering or exiting that group of parts:

zone.playerEntered:Connect(function(player)
    print(("%s entered the zone!"):format(player.Name))
end)

zone.playerExited:Connect(function(player)
    print(("%s exited the zone!"):format(player.Name))
end)

Or you can use methods to retrieve an array of everyone within:

local playersArray = zone:getPlayers()

You can find these details at the docs.

You can find an Ambience example (which checks for the local player instead of players) under StarterPlayerScripts at the ZonePlus playground:

1 Like

Thank you for the Information!

@Lobestone @R_alatch Detection support is finally here with the release of v2.1.0:

You can learn all about this under the new Optimisations section of the docs:

Feedback on anything you discover would be much appreciated! You should find ZonePlus scaling for hundreds to thousands of players when applying the new optimisations (such as setting Detection to Centre).

1 Like

Thanks, I’ll try it out for sure.

It seems to think I’m going in and out of the zone when I have one arm inside. Did I do something wrong? https://gyazo.com/e012433fdd227ef86c7bd5535e9e465f

local zoneService = require(game:GetService("ReplicatedStorage").Zone)
local safeZone = zoneService.new(workspace.SafeZone)

safeZone.enterDetection = safeZone.enum.Detection.WholeBody
safeZone.exitDetection = safeZone.enum.Detection.Centre

safeZone.playerEntered:Connect(function(player)
	player.Safe.Value = true
end)

safeZone.playerExited:Connect(function(player)
	player.Safe.Value = false
end)

What’s going on is this warning here:

This occurs because as soon as the player enterers the zone, its detection snaps to ‘Centre’, however since Centre only captures the very central position, the player has now exited the zone, and it repeats and repeats until the players centre is within the zone or the whole body is outside.

This isn’t a bug, it’s more of a design pattern you shouldn’t be implementing (hence the warning, I only realised this after making the feature).

You’re welcome to set enterDetection to Centre and exitDetection to WholeBody, however the other way around just won’t work. Your next best alternative is keeping both exit and enter detection the same.

Oh, okay. I guess I’ll just set both to center. How do I set both detection methods at the same time because I didn’t really understand the use [setDetection] part?

The introduction page explains it best:

Simply give the name of the enum item you wish to apply and it will set both the exitDetection and enterDetection properties:

zone:setDetection("Automatic")
zone:setDetection("Centre")
zone:setDetection("WholeBody")

Enum details found here:

1 Like

Is it possible to make it worked with lighting and atmosphere effect?

Depends what you want to do? If you want to change a Lighting property when a player enters of exits a zone then that will be easy enough.

1 Like

Do you have any examples of this?

You can find examples at the docs and playground.

As a quick demo, you can do something like the following once you’ve set your group of parts:

local Zone = require(game:GetService("ReplicatedStorage").Zone)
local zoneGroup = workspace.YourGroupOfParts
local zone = Zone.new(zoneGroup)
local lighting = game:GetService("Lighting")
  
zone.playerEntered:Connect(function(player)
    lighting.ClockTime = 0
    lighting.FogColor = Color3.fromRGB(0, 0, 0)
    lighting.FogEnd = 100
end)

zone.playerExited:Connect(function(player)
    lighting.ClockTime = 14
    lighting.FogColor = Color3.fromRGB(192, 192, 192)
    lighting.FogEnd = 100000
end)
1 Like

Thank you so much! I’ll try do it when I get home today.
Also will this worked with player client that only affects to anyone who enter it?

Also is it going in the model or something?

If you wanted only the client to detect when entering and exiting a zone, you would instead use localPlayerEntered and localPlayerExited within a LocalScript in StarterPlayerScripts:

zone.localPlayerEntered:Connect(function()
    --
end)

zone.localPlayerExited:Connect(function()
    --
end)

The playground is currently the best demo - copy and modify it where you need. You’ll likely be interested in ‘AmbientZone’:

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

We’re aiming to create some tutorials in the future to help out with this.

1 Like