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

Your code appears to be fine at a glance. Can you send a picture of zoneParts and their descendants in workspace? Have you made sure the parent is a model or folder?

3 Likes

Sure.
zoneparts

1 Like

I’m making a room detection system for my game and it’s worked great so far to detect which room each player is in.
I know this isn’t a feature of the module, and neither is it intended, but what do you suggest for detecting non-player objects such as a thermometer detecting which room it is currently in.

There’s a few methods you could use in your scenario and it ultimately depends on how your tools/objects behave (i.e. can they move at all, can they be picked up by players, etc).

First idea which springs to mind: group invisible parts together to represent a room and place them slightly below the room itself, then whenever you need to know which room the thermometer is in, fire a raycast downwards and if it hits one of these parts you can deduce which room its in.

2 Likes

Has anyone used this for hitboxes? All the existing solutions I have looked at aren’t good for my use case so far. using just regular .Touched doesnt reliably fire if the hitbox isnt moving.

I was wondering this aswell while looking at this topic.

Zone+ can be used to generate hitboxes. Keep in mind it’s primarily intended to work with static areas as apposed to dynamically changing areas. For this reason I’d explore other resources such as swordphin’s Raycast Hitbox module:

3 Likes

Hey :wave: I’ve been using Zone+ recently (it’s an amazing module). However, I’ve been running into some problems recently.

I’ve been making two zones for a music changer and an environment name popup thingy. There has been this bug and it’s IS SO FRUSTRATING. This is happening on the client (I use it correctly):

This is a class that is integrated with Quenty’s Binder class

function EnvironmentRegion:_connectModel(model)
	local zone = Zone.new(model)
	
	zone.playerAdded:Connect(function(player)
		print(player.Name, "has entered", self:GetEnvironmentName())
		EnvironmentName:Set("DisplayedText", self:GetEnvironmentName())
	end)
	
	zone.playerRemoving:Connect(function(player)
		print(player.Name, "has left", self:GetEnvironmentName())
	end)
	
	self._maid:GiveTask(zone)
	zone:initClientLoop(0.01)

	print("Created EnvironmentRegion Zone For Model:", model:GetFullName())
end
-- I know this says MusicChangePart but it is actually a model (i'm looking to
-- change the name later)
function MusicChangePart:_connectModel(model)
	local zone = Zone.new(model)

	zone.playerAdded:Connect(function(player)
		print("Switch background music")
		SwitchBackgroundMusic({
			SoundId = self:GetAudioAssetId(),
		})
	end)
	
	zone.playerRemoving:Connect(function(player)
		print("Left background")
		SwitchBackgroundMusic({
			SoundId = SwitchBackgroundMusic.DefaultBackgroundMusic,
		})
	end)
	
	self._maid:GiveTask(zone)
	print("Created MusicChangePart Zone For Model:", model:GetFullName())
	zone:initClientLoop(0.01)
end

The major problem is that the behavior is extremely inconsistent. Sometimes, one zone works. Sometimes the other. Sometimes both zones work, and sometimes none work. It is really frustrating.

Also, It prints that the zones are created (both zones). I think it’s something to do with playerAdded and playerRemoving.

No errors at all.

Thanks.

Will this worked with lightings and atmospheres on only player client that won’t affect other players client?

@saSlol2436 DM’d to look into it further

@DeathLilian Assuming you setup your zones on the client (e.g. using a LocalScript within StarterPlayerScripts) and utilise methods like zone:initClientLoop() (instead of initLoop) then this is perfectly fine :+1:

You can find a coded example of an ambient system here:

2 Likes

Thank you so much @ForeverHD!!

@ForeverHD
Also is there a way to replace sounds to lighting/atmosphere inside the script? (I just come back to Roblox after few months break)

You can modify the properties and children of lighting within game:GetService("Lighting") then use TweenService:create to transition these in and out. Feel free to ask in #help-and-feedback:scripting-support for anymore general help!

1 Like

@ForeverHD Ah okay I was thinking about making a planet system with this but I can’t figure it out how to get it worked.

Hello!

I’ve recently started messing with this a system a bit, and noticed the topic of “performance”. In an attempt to reduce the lag or performance that may be caused, I’ve changed the value of the loopdelay on row 297 on the “Zone” script, from 0.5 to a higher value. How greatly would this improve performance? Does it improve performance at all?


(where I’ve edited the script)
Thanks!

Increasing the delay from 0.1 to 1 second for example will reduce checks by 540 per minute (600 to 60). This will improve performance however the significance of this depends on a few factors you’ll have to test and determine yourself. You can find more about these under ‘Best Practises’

2 Likes

Hello, i am having issues with your module.

The previewed part is my zone but it only fires playerentered event when i stand on the wooden platform, do you have any idea why this happened? i think zone+ is conflicting with the terrain.

I checked my scripts multiple times and i can guarantee you that its not my scripting error

Edit: I tried to make my platform bigger and it still behaved like it did before, I think its my issue but do you have any idea why it happened?

Edit2: I copied my platform made it bigger turned off cancollide and made it a zone now it behaves like i want so yeah problem solved ignore this post

Can you make it so you can make it search through a table of Instances for createZones instead of an instance container?

I have some NPC’s and not all their parts is the Zone I want so I store them in a table.

Sure thing, you can do this for v2 which takes containers (models, folders, etc as before), a single basepart or tables, as you need, for the ‘group’ argument:

(Note: v2 has a completely new API, we’ll officially release next week)

1 Like

Just checked it out, works amazing. Thanks.