Zone+ v1 (deprecated) | Retrieving players within an area/zone

This method only accounts for rectangular shapes, therefore is only effective for square-like zones.

Thereā€™s this strange behavior when parts overlap or are located in a certain way under others.
https://cdn.discordapp.com/attachments/644398962614206464/717502867774373888/Zone_Playground_-_Roblox_Studio_2020-06-02_18-12-44.mp4

2 Likes

This is an awesome module, i really needed this, i was a bit scared of using it because i thought it was something very hard to use, however, i was wrong, itā€™s very easy to use and useful for alot of stuff, well, i got a small problem:

I already have readed the API i needed for my code, and i donā€™t know if i wrote something correctly, this code that i have is a vote system, in summary, this would be a loop creating and destroying a zone:

While true do
...
for MapNumber, Map in pairs(ChoosenMaps) do --Three times creates a Zone
		local VoteZone = game.Workspace:FindFirstChild("Zone"..MapNumber) --Gets the zone model
		local Zone = ZoneService:createZone("Vote"..MapNumber, VoteZone, 15) --Creates the zone
		--// More code would be here :P //--
		Zone:initLoop()
		VoteEnded:GetPropertyChangedSignal("Value"):Connect(function() 
			if VoteEnded.Value then --It actually changes
				Zone:endLoop() --The loop ends
				Zone:destroy() --The zone created gets destroyed
			end
		end)
	end
...
wait(10)
end

However, when the code gets repeated (because of the While true do), i get the error mentioning that the first Zone created already exists, when i already have deleted it. I donā€™t know if i wrote something not correctly, if itā€™s a bug, or if everything is ok with the module so i can fix my code, thanks for reading :slight_smile:

When you create a zone via the ZoneService (i.e. ZoneService:createZone(name, group) it must also be removed via the ZoneService (i.e. ZoneService:removeZone(name)).

Since youā€™re creating and destroying lots of zones, and donā€™t need to reference it outside your section of code, youā€™re better of directly constructing a zone via the Zone object (instead of using the ZoneService), so now your code can look like:

local ZonePlus = require(4664437268) -- Initiate Zone+
local Zone = require(ZonePlus.Zone)

While true do
...
for MapNumber, Map in pairs(ChoosenMaps) do --Three times creates a Zone
		local group = game.Workspace:FindFirstChild("Zone"..MapNumber) --Gets the zone model
		local zone = Zone.new(group, 15) --Creates the zone
		--// More code would be here :P //--
		zone:initLoop()
		VoteEnded:GetPropertyChangedSignal("Value"):Connect(function() 
			if VoteEnded.Value then --It actually changes
				zone:destroy() --The zone created gets destroyed (zone:destroy() calls endZone for you)
			end
		end)
	end
...
wait(10)
end
1 Like

Hi @ForeverHD!

You might be able to upgrade Zone+ by utilizing this information:

You might want to consider using TouchEvents now that we know how to make it reliable

Zone+ is primarily intended for server-side use (explained here: Should Zone+ support the client, or completely advise against it? Ā· Issue #30 Ā· nanoblox/core Ā· GitHub), as apposed to that proposed method which can only function client-sided.

Hi,
I have a question is there way i can update zone or it already updates? For example i have a folder and there 0 objects i created zone and then i added some parts in folder. will these parts be counted to zone or i need update zone? If i need to update zone how i can do it?

Zones are dynamic; they listen for changes in children (i.e. the adding or removing of a part) and the resizing and positioning of these children. So yep, if youā€™re adding some parts to its folder, the zone will automatically update for you :+1:

2 Likes

Oh also is there way i can detect which part player touching? I want to use it to detect when player near npc and to know near what npc are player near i used ObjectValue inside parts.

You can achieve this with zone:getPlayer(player) which returns the part a player is standing on or within, and its intersection vector:

2 Likes

Zone+ now supports client-use!

Originally Zone+ was intended only for server-use, however many developers had been abusing its functionality for the client (explained in more detail here: Should Zone+ support the client, or completely advise against it? Ā· Issue #30 Ā· nanoblox/core Ā· GitHub)

To solve this, weā€™ve modified the behaviour of zone:getPlayer(player) and zone:getPlayers(), and introduced a new method:

  • zone:initClientLoop() - for when you only need to check the localplayer (and not every player in the server)

New Ambient Areas example:

Easily play sounds within designated areas (source code found within StarterPlayerScripts in the Zone+ Playground).
https://thumbs.gfycat.com/TangibleFamiliarBufeo-mobile.mp4

Important (if you previously used Zone+ on the client)

If you have previously been using Zone+ on the client, make sure to update your events section to call zone:initClientLoop() instead of zone:initLoop(). This significantly improves performance as redundant Region3 checks are completely ignored, and a raycast is only fired for the local player, as apposed to every player within the zones rough-area.

12 Likes

Can you explain on how to make this Zone+ for a gamepass only Zone. I have little understanding when it comes down to this kind of scripting. For instance, where do I put in ID of gamepass? How big can Zone be?

  1. Setup a dictionary which will be used to record who in a server has the gamepass.

  2. When a player joins the server, use UserOwnsGamePassAsync to verify they own the gamepass, and add them to the dictionary if they do.

  3. Setup PromptGamePassPurchaseFinished to check for when a gamepass is purchased. If the gamepass matches your desired gamepass, add them to the dictionary.

  4. Use the zone.playerAdded event to check for when a player enters your exclusive zone. If they are not within the dictionary previously defined, remove or block them from the zone (e.g. teleport away, kill, etc). You can find more about setting up zones here: https://1foreverhd.github.io/HDAdmin/projects/zoneplus/about/#example-server-sided

3 Likes

I have small experience when it comes to scripting. For step 1, how would I setup a dictionary? Also, when setting this up which script would it go into out of these 3? image

For instance would I have to add the Marketplaceservice script myself or is it already added?

echt geil, werde ich in zukunft mal gebrauchen kƶnnen :slight_smile: !!!

I notice the code uses GetTouchingParts, would this not be making your code a little outside server use? I believe you create a Touched event to make GetTouchingParts to work so it could create a server side risk even if it only supports the rest of the module.

Or maybe I am mistaken or was seeing an outdated version.

Hey dude @ForeverHD!

Roblox added a new feature New RaycastParams Property, Deprecating Old Raycast Functions

You should definitely update the module~

1 Like

GetTouchingParts is used to form ā€˜clustersā€™ within a zone when its constructed, not to detect players/parts within that zone. While not necessary, clusters provide more precise sub-areas within a zone, which enables more efficient point generation using getRandomPoint(). Touched events arenā€™t used alongside GetTouchingParts for this. The cluster system may be removed entirely going forwards as I explore further ways to generate random points.

2 Likes

You can learn more about tables, dictionaries and arrays here, and can view coded examples of Zone+ here. For everything else, I recommend becoming more familiar with lua and the Roblox API and asking further questions within Help and Feedback.

1 Like

Nice, Iā€™ve replaced the deprecated method with the new ones:

1 Like