Hi! I'm trying to make a turret that aims bullets at player and damages them, everything working fine, except when I add the Ray.new to see if something is on the way, like a wall, it is always gives me the msg that something on the way. Thanks!
``lua
local fireWhenPlayer = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local bullet = replicatedStorage.Bullet
local turretBase = game.Workspace.TurretBase
local turretFire = game.Workspace.TurretFire
local fireRate = 0.3
local bulletSpeed = 100
local bulletDamage = 10
local agroDistnace = 50
local bulletFolder = Instance.new("Folder")
bulletFolder.Parent = script.Parent
bulletFolder.Name = "BulletFolder"
while wait(fireRate) do
local target
for i, v in pairs(game.Workspace:GetChildren()) do
local hum = v:FindFirstChild("Humanoid")
local upperTorso = v:FindFirstChild("UpperTorso")
if hum and upperTorso then
if (upperTorso.Position - turretFire.Position).Magnitude < agroDistnace then
local newRay = Ray.new(turretFire.Position, (upperTorso.Position - turretFire.Position).Unit * agroDistnace)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(newRay, {turretFire, turretBase})
if hit == upperTorso then
target = upperTorso
else
print("Something on the way")
end
end
end
end
if target then
...
end
``
** You are now Level 1! **