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

Need to show code as well as you may not be doing it correctly.

This script is used for hitbox. (probably not the best idea, but just fits in my case.)
Whenever a projectile is throwed this script is enabled, and first time just works fine, but whenever I die, resetting or not, the script just dies, and doesn’t outputs anything.

local Projectile = script.Parent
local Visual = game.ReplicatedStorage.ToolsSettings.StinkGranade
local Settings = game.ReplicatedStorage.ToolsSettings.Mine

local Tween = game:GetService("TweenService")
local ZonePlus = require(game.ReplicatedStorage.Zone)

local Owner = script.Parent:WaitForChild("Owner").Value

local Survivor = game.Teams.Survivors
local Frog = game.Teams.Frogs
local Players = game.Players

local PlayersInHitbox = {}

local TouchedGround = false
local AlreadyUsed = false
local HitOutline
local HitBox
local HitNew
local IsAdd = false

local ItemInfo = {

	-- Sons
	GroundSFX = "rbxassetid://379275626",
	DamageSFX = "rbxassetid://2648568095",
	LaughSFX = "rbxassetid://5445066989"
}

function FirstTouched(t)
	if IsAdd == false then
		IsAdd = true
	HitBox = Visual.Visual.BoxHit:Clone()
	HitBox.Parent = Projectile
	HitBox.Anchored = true
	HitBox.Position = Projectile.Position
	HitBox.Smoke.Enabled = true	
	HitBox.Size = Vector3.new(5, 5, 5)	
	
	local VisualScript = Visual.Visual.Visual:Clone(); VisualScript.Parent = HitBox; VisualScript.Enabled = true
		
	Tween:Create(HitBox, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0), { Size = Vector3.new(30.029, 30.029, 30.029) }):Play()	
		
	Projectile.Sounds.Break.TimePosition = 1.25
	Projectile.Sounds.Break:Play()
	Projectile.Sounds.Gas:Play()
		
	Projectile.Anchored = true
	Projectile.Transparency = 1
	Projectile.Content.Transparency = 1
	Projectile.Tamp.Transparency = 1	
		
	Projectile.CanCollide = false
	Projectile.Content.CanCollide = false
	Projectile.Tamp.CanCollide = false
		

	end
end

function EnteredHitBox(player)
	local Character = player
	local CurrentPlayer = player.Character
	
	PlayersInHitbox[player] = true
	while PlayersInHitbox[player] do
		if not PlayersInHitbox[player] then
			break
		end
		player.Character:FindFirstChild("Humanoid"):TakeDamage(5)
		
		local Select = math.random(1, 2)
		
		local Cough = script.Cough:Clone()
		Cough.Parent = CurrentPlayer.PrimaryPart
		
		if Select == 1 then
		Cough.SoundId = "rbxassetid://6333150436"
		else
		Cough.SoundId = "rbxassetid://6333150725"
		end	
		Cough.PlayOnRemove = true
		Cough:Destroy()
		wait(3)
			end
end

function LeavedHitBox(player)
	local Character = player
	local CurrentPlayer = player.Character
	
	PlayersInHitbox[player] = nil
end

Projectile.Touched:Connect(function()
	
	FirstTouched() wait()
	HitNew = ZonePlus.new(script.Parent.BoxHit)
	
	HitNew.playerEntered:Connect(function(plr)
		EnteredHitBox(plr)
	end)
	
	HitNew.playerExited:Connect(function(plr)
		LeavedHitBox(plr)
	end)
	
end)



oh sorry!! but I had to use lighting zone that from playground file but idk why it not work with current version that not need to be in folder…

Change your zone module to the latest one and show your script/location after migrating and see if it works.

i’m using latest version but I can try show it tomorrow it late in here for me.

I have an issue using it with streaming enabled, I am currently using ZonePlus for lighting, but it does not work when I have streaming enabled, when it is disabled it works fine, but when it is enabled it does not. I have tried adding WaitForChild() but it doesn’t seem to work too. Any solution for this?

Also, here is the script I’m using for lighting:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Zone = require(ReplicatedStorage.Modules.Zone)
local ZoneController = require(ReplicatedStorage.Modules.Zone.ZoneController)
local Lighting = game:GetService("Lighting")

for i, v in pairs(game.Workspace:WaitForChild("InteriorLights"):GetChildren()) do
	local AllParts = Zone.new(v)

	AllParts:bindToGroup("AmbientAreas")

	AllParts.localPlayerEntered:Connect(function()
		Lighting.Ambient = Color3.fromRGB(255, 255, 255)
	end)

	AllParts.localPlayerExited:Connect(function()
		Lighting.Ambient = Color3.fromRGB(70, 70, 70)
	end)
end
1 Like

Hey, I never used an open source project like this and is intrested is this future proof?

Is this recommended for melee hitboxes?

1 Like

If you track too much items (14 for me) :trackItems() it will completely break and getItems will throw error attempt to index nil with CFrame
getParts() will also return empty array
and events like itemEntered and itemExited wont fire

absolutely essential to complex games, thank you all for the time you put into this free resource!

Starting to get this as well. It can be buggy and inconsistent.

2 Likes

Update: Don’t create a zone for the same part in two separate scripts. It’ll bug out. That was the issue with me, but I will see if more items will cause issues too.

2 Likes

I am using zone+ to be incorporated with a trunk system and other gui based store locations
the issue is

  1. until recently it randomly works and doesn’t for players, i could be playing as player1 and it won’t run past the initializing constants and for player2 it works

  2. i can’t get the zone’s to update if a new car is added to the folder

i tried doing trunkzone:_update(), etc and childadded functions and nothing works

local function findTrunks(carsFolder)
	for _, trunk in ipairs(carsFolder:GetChildren()) do

		if trunk.Name == "Trunk" then

			local trunkzone = Zone.new(trunk)

			trunkzone.localPlayerEntered:Connect(function()
				
				-- my function here
			end)
			trunkzone.localPlayerExited:Connect(function()
				-- exit function here
			end)
		end
		findTrunks(trunk)
	end
end
findTrunks(carsFolder)

Will this ever get a Wally integration?

1 Like

The issue was with Streaming Enabled. Despite using :WaitForChild("Water_2") and whatnot, I was having issues.


Edit: nevermind to the nevermind. I’m also using collection service and trying to get zones to work with that. Going one error at a time and working through it.

Edit 2: Collision detection works fine now for me, I got it working.

my old reply

Hi,
I’m using a custom character and trying to implement this module into my game PB & Jay. I’ve read through the documentation, read through this post, and have watched the tutorial in its entirety. I’ve been trying to get this module to work with my custom water part system, but have been unable to detect collisions at all.


Here's the code

----- Zone Module -----
-- https://devforum.roblox.com/t/zoneplus-v320-construct-dynamic-zones-and-effectively-determine-players-and-parts-within-their-boundaries/1017701

local Zone = require(game:GetService("ReplicatedStorage").Zone)
local container = workspace:WaitForChild("Water_2").hitbox
local zone = Zone.new(container)

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

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

Here's a video of collision detection not working


If I need to provide more info, don’t hesitate to ask. I’ll look into the module code and whatnot to try finding a solution, but if you (@ForeverHD) could give me any info, that’d be great.

Thanks,
Reditect

Have you tried setting CanQuery to true because apparently you need CanQuery set to true in order for it to work. (most of the time)

1 Like

Yep.
image

I’ve gotten the collisions to work with ZonePlus, now it’s just my implementation of a swimming system in my custom Animate script that I need to fix.


Update, 8/1/2023:

Been testing for more than an hour sifting through the code of the module itself. My issue was that it was checking for a “Head” but my custom character’s head’s name was “head”. Not capitalized. Be sure you change what the code is looking for or you change the head name to “Head”.

1 Like

I am facing a similar issue, but based on my research, it seems that whenever a part is destroyed within a zone, the zonevolumecustom changes to 256, whereas previously it was in the millions. This behavior seems suspicious.

the Error:



2 Likes

I have a question about ZoneEvents. Is it possible to disconnect these events whenever we no longer need them?

So if I’m running a script similar to this one:

local item = character:FindFirstChild("HumanoidRootPart")
zone:onItemEnter(item, function()
    print("The item has entered the zone!"))
end)

But it tracks the humanoid root part of every player in the game, and then a player decides to leave the game, will it be possible to disconnect the event that is tracking it? Or is this done automatically?

Anyone know how to make a Zone created using fromRegion visible?