From my other post called “Creating a Director AI, Possible?” I got a solution but i got a error once i spawned zombies, And it wasn’t straight connecting with the zombies.
The lines was this:
local lineOfSightRaycastParams = RaycastParams.new()
function hasLineOfSight(pointA, pointB)
local result = game.Workspace:Raycast(pointA, pointB - pointA, lineOfSightRaycastParams)
return result == nil
end
function isSpawnPointInSightOfAnyPlayer(spawnPoint)
for _, player in pairs(game.Players:GetPlayers()) do
-- Dead or otherwise unspawned players have no character
-- TODO: Handle these cases so
local head = player.Character and player.Character:FindFirstChild("Head")
if not head then continue end
if hasLineOfSight(head.Position, spawnPoint) then
return true
end
end
return false
end
while wait(0.05) do
for i,v in pairs(game.Workspace.SpawnPoints:GetChildren()) do
if isSpawnPointInSightOfAnyPlayer(v) == false then
InfectedModule.SpawnZombie(v)
end
end
end
while wait() do
for i,v in pairs(game.Workspace.SpawnPoints:GetChildren()) do
if isSpawnPointInSightOfAnyPlayer(v) == false then
InfectedModule.SpawnZombie(v)
end
wait(1)
end
end
I believe there was a different way for checking the line of site for an npc/player, where you use Unit on a vector3 value and also use :Dot(). I haven’t looked into it, but i had seen it in a tutorial by a few youtubers. Might that help?