Zone entry and exit not detected after death (Possible Zoneplus bug)

  1. What do you want to achieve? I want the zone entry and exit to even be detected after the player’s death so the CanPlace value would return either true or false.

  2. What is the issue? Once I die, it doesn’t detect if I have entered the zone or left the zone and the CanPlace variable defaults to false.

  3. What solutions have you tried so far? I tried using zone:untrackItem(), zone:destroy(), tried defining the character once the tool got activated. I’ve debugged the code and it’s definitely happening cause of the zone not detecting entry and exit anymore.

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local Zoneplus = require(ReplicatedStorage:WaitForChild("Zone"))
local CanPlace = false

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local PlacementOptions = LocalPlayer:WaitForChild("PlacementOptions")
local Material = PlacementOptions.Material
local Colour = PlacementOptions.Colour

local PlayerPlot = LocalPlayer:WaitForChild("PlayerPlot")

local GUI = LocalPlayer.PlayerGui:WaitForChild("Placement Options")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PreviewBrick
local Movement

function snap_to_grid(MousePos, grid_unit)
	return math.round(MousePos / grid_unit) * grid_unit
end

local Zone
local function CreateZone(Brick)
	task.spawn(function()
		repeat task.wait() until Brick and PlayerPlot.Value
		local ZoneCFrame = CFrame.new(PlayerPlot.Value:WaitForChild("Area").Position)
		local ZoneSize = PlayerPlot.Value:WaitForChild("Area").Size
		Zone = Zoneplus.fromRegion(ZoneCFrame, ZoneSize)

		Zone.itemEntered:Connect(function(item)
			if item == Brick then
				print("Entered.")
				CanPlace = true
			end
		end)

		Zone.itemExited:Connect(function(item)
			if item == Brick then
				print("Exited.")
				CanPlace = false
			end
		end)
		
		Zone:trackItem(Brick)
	end)
end

local function OnEquip()
	print("Equipped.")
	GUI.Enabled = true	
	PreviewBrick = Instance.new("Part", workspace)
	PreviewBrick.Size = Vector3.new(2, 2, 2)
	PreviewBrick.Name = "PreviewBrick"
	PreviewBrick.Anchored = true
	PreviewBrick.Transparency = .3
	PreviewBrick.CanQuery = false
	PreviewBrick.CanCollide = false
	PreviewBrick.CastShadow = false

	CreateZone(PreviewBrick)
	
	UserInputService.InputBegan:Connect(function(input)
		task.spawn(function()
			if input.KeyCode == Enum.KeyCode.R then
				while UserInputService:IsKeyDown(Enum.KeyCode.R) do
					print("aughhhhh")
					PreviewBrick.Orientation = PreviewBrick.Rotation + Vector3.new(0, 2, 0)
					task.wait(0.05)
				end
			end
		end)
	end)
	
	Movement = RunService.RenderStepped:Connect(function()
		if Material.Value ~= "" then
			PreviewBrick.Material = Material.Value:reverse():split(".")[1]:reverse()
		end
		PreviewBrick.Color = Colour.Value
		
		local Mouse = LocalPlayer:GetMouse()
		local MousePosition = Mouse.Hit.Position + Vector3.fromNormalId(Mouse.TargetSurface) * PreviewBrick.Size / 2
		
		PreviewBrick.Position = Vector3.new(
			snap_to_grid(MousePosition.X, 1),
			snap_to_grid(MousePosition.Y, 1),
			snap_to_grid(MousePosition.Z, 1)
		)
		
		if Vector3.new(PreviewBrick.Position.X, PreviewBrick.Position.Y, PreviewBrick.Position.Z).Y < 1.5 then
			PreviewBrick.Position = Vector3.new(PreviewBrick.Position.X, 2, PreviewBrick.Position.Z)
		end
	end)
end

local function Unequip()
	script.Parent.Parent = LocalPlayer.Backpack
	GUI.Enabled = false
	if Movement then
		Movement:Disconnect()
		PreviewBrick:Destroy()
	end
end

script.Parent.Activated:Connect(function()
	local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	print((PreviewBrick.Position - HumanoidRootPart.Position).Magnitude)
	print(CanPlace)
	if (PreviewBrick.Position - HumanoidRootPart.Position).Magnitude < 30 and CanPlace then
		script.Parent:WaitForChild("PlaceBrick"):FireServer(Material.Value, Colour.Value, PreviewBrick.Position, PreviewBrick.Orientation)
	end
end)

script.Parent.Equipped:Connect(OnEquip)
script.Parent.Unequipped:Connect(Unequip)

If anyone wants to test, here’s the game’s link: BandQueenForever's Place Number: 11 - Roblox

]]

local Zoneplus = require(ReplicatedStorage:WaitForChild(“Zone”))

local RunService = game:GetService(“RunService”)

local PreviewBrick
local Movement

function snap_to_grid(MousePos, grid_unit)
return math.round(MousePos / grid_unit) * grid_unit
end

local Zone
local function CreateZone(Brick)
task.spawn(function()
local ZoneCFrame = CFrame.new(Vector3.new(0, 20, 0))
local ZoneSize = Vector3.new(100, 100, 100)
Zone = Zoneplus.fromRegion(ZoneCFrame, ZoneSize)

Zone.itemEntered:Connect(function(item)
if item == Brick then
print(“Entered.”)
task.spawn(function()
Brick.Transparency = .3
task.wait(1)
Brick.Transparency = 0
task.wait(1)
Brick.Transparency = .3
task.wait(1)
Brick.Transparency = 0
task.wait(1)
Brick.Transparency = .3
task.wait(1)
Brick.Transparency = 0
end)
end
end)

Zone.itemExited:Connect(function(item)
if item == Brick then
print(“Exited.”)
end
end)

Zone:trackItem(Brick)
end)
end

local function OnEquip()
PreviewBrick = Instance.new(“Part”, workspace)
PreviewBrick.Size = Vector3.new(2, 2, 2)
PreviewBrick.Name = “PreviewBrick”
PreviewBrick.Anchored = true
PreviewBrick.Transparency = .3
PreviewBrick.CanQuery = false
PreviewBrick.CanCollide = false
PreviewBrick.CastShadow = false

CreateZone(PreviewBrick)

UserInputService.InputBegan:Connect(function(input)
task.spawn(function()
if input.KeyCode == Enum.KeyCode.R then
while UserInputService:IsKeyDown(Enum.KeyCode.R) do
PreviewBrick.Orientation = PreviewBrick.Rotation + Vector3.new(0, 2, 0)
task.wait(0.05)
end
end
end)
end)

Movement = RunService.RenderStepped:Connect(function()
local Mouse = LocalPlayer:GetMouse()
local MousePosition = Mouse.Hit.Position + Vector3.fromNormalId(Mouse.TargetSurface) * PreviewBrick.Size / 2

PreviewBrick.Position = Vector3.new(
snap_to_grid(MousePosition.X, 1),
snap_to_grid(MousePosition.Y, 1),
snap_to_grid(MousePosition.Z, 1)
)

if Vector3.new(PreviewBrick.Position.X, PreviewBrick.Position.Y, PreviewBrick.Position.Z).Y < 1.5 then
PreviewBrick.Position = Vector3.new(PreviewBrick.Position.X, 2, PreviewBrick.Position.Z)
end
end)
end

local function Unequip()
script.Parent.Parent = LocalPlayer.Backpack
if Movement then
Movement:Disconnect()
PreviewBrick:Destroy()
end
end

script.Parent.Equipped:Connect(OnEquip)
script.Parent.Unequipped:Connect(Unequip)

If the player dies, can’t you just set CanPlace to false? Like, using Humanoid.Died:Connect()?

Read what I posted, I don’t want that. I want the player to be able to place again after they respawn but they can’t.

What the hell is this mate? lmao

I suppose you have to reset the Character variable, as it will still refer to the now-dead-and-removed model of the player before respawning.

LocalPlayer.CharacterAdded:Connect(function(Char)
	Character = Char
end)

There’s nothing wrong with the character because I checked that as well. The problem is that Zoneplus doesn’t detect the entry and exit of the part after the player respawns.

There’s is nothing wrong, yes. But you can’t compare Character == LocalPlayer.Character after a respawn, for they don’t have the same models.

Try the code I sent in your LocalScript.

Still didn’t work. The script is parented under a tool and you can clearly see it gets the player’s character once the player clicks on the tool. The problem is with Zoneplus, not the character.

1 Like

Figured I’d bump this post as I still need help with this. It’s a major issue.

1 Like

Bumping again, nobody has helped me with this for the past few weeks and whenever I try to repost, I get warned and the repost gets taken down. How am I supposed to get a solution if I can’t bump? Whatever, I’ll still bump, nobody’s stopping me.

your not alone. i need help with this problem too. im working on a game that requires zones. bumping this topic. anyone?

1 Like

I was able to fix this by approaching this alternatively. I used one of the two functions found in the API. findItem and findPart. Some issues still occur though, but it worked.

How exactly? I need to fix this error ASAP and I can’t adapt this “fix” for my code… :confused: