The :Dot() function works but permits you look through walls.
I meant on the spawn location & head location.
What’s the issue now though? Isn’t everything fixed with the cooldown?
This is what i want it to do:
In general, the Infected are spawned out of sight from the Survivors, and are de-spawned after the Survivors move out of range
Sorry, I quoted the wrong line, it was supposed to be this line:
When you use the spawn part as the argument for the function isSpawnPointInSightOfAnyPlayer, in this line:
It then places the spawn part as the argument for the hasLineOfSight function, and if you look at that function, in this line:
You are attempting to subtract the spawn part from the head position, which would not make sense, since one is an instance and the other is a Vector3 value. Hope this solves your problem.
Then what should i do to fix it?
Change this line:
to this:
if isSpawnPointInSightOfAnyPlayer(v.Position) == false then
Not working, It’s still spawning the zombie when i look at it
And plus that was what i have tried already.
There is also this function here:
function isSpawnPointAvailable(spawnPoint)
return not isSpawnPointInSightOfAnyPlayer(spawnPoint)
--There will probably be other conditions for spawning somewhere
end
I think I spotted the problem. In your function hasLineOfSight, as shown right here,
function hasLineOfSight(pointA, pointB)
local result = game.Workspace:Raycast(pointA, pointB - pointA, lineOfSightRaycastParams)
return result == nil
end
the result would never be nil, so in your while loop, it will forever spawn zombies. If you know what raycasting does, it basically sends a ray from a starting position, then goes in the direction you gave in the second parameter, and the result returns the first thing that it hits (or nil if it hits nothing). But since in your RaycastParams, you never set a blacklist, which means that the moment you send the raycast, it will hit the player’s head, and therefore the function will return false.
Here’s a solution:
function hasLineOfSight(partA, partB)
local lineOfSightRaycastParams = RaycastParams.new()
lineOfSightRaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
lineOfSightRaycastParams.FilterDescendantsInstances = {partA, partB}
local result = game.Workspace:Raycast(partA.Position, partB.Position - partA.Position, 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, spawnPoint) then
return true
end
end
return false
end
while true do
task.wait()
for i,v in pairs(game.Workspace.SpawnPoints:GetChildren()) do
if isSpawnPointInSightOfAnyPlayer(v) == false then
InfectedModule.SpawnZombie(v)
end
end
end
Unable to cast value to Object in line 6
lineOfSightRaycastParams.FilterDescendantsInstances = {partA, partB}