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)