Build system blocking detection

hello im making a “build to survive zombies” type map feature but im trying to check if the build is blocking the zombie spawning location, when i do that its very buggy and you can simply bypass that limit.
zombies have pathfind and testing them turn out very bad on my builds
anyways, is there a way to fix this or make this better?

local Tool = script.Parent
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local PosX,PosY,PosZ
local Grid = 2
local function SnapToGrid()
	PosX, PosY, PosZ = math.floor(Mouse.Hit.X / Grid + .5) * Grid, math.floor(Mouse.Hit.Y / Grid + 1) * Grid, math.floor(Mouse.Hit.Z / Grid + .5) * Grid
end
local PathfindingService = game:GetService("PathfindingService")
function GetPath(PositionStart,PositionEnd)
	local Path = PathfindingService:CreatePath()
	Path:ComputeAsync(PositionStart,PositionEnd)
	return Path
end

Tool.Activated:Connect(function()
	SnapToGrid()
	local MyPath = GetPath(Vector3.zero+Vector3.new(0,2,0),Vector3.new(PosX,PosY,PosZ))
	if MyPath.Status == Enum.PathStatus.Success and MyPath.Status ~= Enum.PathStatus.NoPath then
	local Part = Instance.new("Part",workspace)
	Part.Anchored = true
	Part.Size = Vector3.new(2,2,2)
		Part.Position = Vector3.new(PosX,PosY,PosZ)
	else
		if not workspace:FindFirstChild("Alert") then
		local message = Instance.new("Message",workspace)
		message.Text = "You can't place a part that blocks monster's path!"
		message.Name = "Alert"
		game:GetService("Debris"):AddItem(message,1.5)
			end
		end
end)
2 Likes

Not sure if this is the best way to do this, but I would check the magnitude between the zombie spawnpoint and the block whenever a player places a block and then check if the magnitude is lower than a specific amount, and if it is, destroy the block, or just not let the player place there.

1 Like

Since you are using a grid system, convert the spawn position to a grid position (similar to how you do in the SnapToGrid function) and check if a block exists in that location, assuming that you store the all created blocks in a dictionary

1 Like

no i want to check if the pathfind is blocked so it wont break the pathfinder, when i do that it doesnt work correctly