Currently making a zombie survival game with a building system. I’m using a pre-existing zombie pathfinding system since I don’t know how pathfinding really works and am currently too lazy to watch an hour long tutorial. It works great, the only issue is that the zombies will stop following the player if the player boxes themselves in. I’ve already made it so the buildings take damage, it’s just this one issue.
Lines that are responsible for pathfinding to a player:
function GetTorso(part)
local chars = game.Workspace:GetChildren()
local chaseRoot = nil
local chaseTorso = nil
local chasePlr = nil
local chaseHuman = nil
local mag = SearchDistance
for i = 1, #chars do
chasePlr = chars[i]
if chasePlr:IsA'Model' and chasePlr ~= zombie then
chaseHuman = getHumanoid(chasePlr)
chaseRoot = chasePlr:FindFirstChild'HumanoidRootPart'
if chaseRoot ~= nil and chaseHuman ~= nil and chaseHuman.Health > 0 and chaseHuman.Name ~= "Zombie" then
if (chaseRoot.Position - part).magnitude < mag then
chaseName = chasePlr.Name
chaseTorso = chaseRoot
mag = (chaseRoot.Position - part).magnitude
end
end
end
end
return chaseTorso
end