-
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. -
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. -
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