local turret = script.Parent
local IgnoreParts = {turret}
local bulletdamage = 15
local bulletspeed = 300
local aggrodist = 50
local firerate = .1
local bullet = game.ReplicatedStorage:WaitForChild("Bullet")
local NewBullet
local update = function()
local isntance = game.Players:GetChildren()
for i, v in pairs(isntance) do
print(typeof(v))
table.insert(IgnoreParts, v.Character)
end
end
while true do
wait()
update()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = IgnoreParts
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local Wall, HitPosition, Normal, Materia = workspace:Raycast(turret.Position, turret.CFrame.LookVector*aggrodist, raycastParams)
if Wall then
else
print("B)")
wait(firerate)
local root = nil
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == script.Parent.Parent.Owner.Value then
target = nil
else
local human = v:FindFirstChild("Humanoid")
root = v:FindFirstChild("HumanoidRootPart")
if human and root and human.Health > 0 then
if (root.Position - turret.Position).magnitude < aggrodist then
else
root = nil
end
end
end
end
if root then
turret.CFrame = CFrame.new(turret.Position, root.Position)
NewBullet = bullet:Clone()
NewBullet.Parent = workspace
NewBullet.Position = turret.Position
NewBullet.Velocity = turret.CFrame.LookVector * bulletspeed
end
root = nil
end
end
why does the turret shoot the player and stop when the player goes behind a wall but does not continue shooting if the player comes from behind the turret
