Need help with Raycasting

local RS = game:GetService("ReplicatedStorage")
local Bullet = RS:WaitForChild("Bullet")

local Turret = script.Parent

local fireRate = 0.5
local BulletDamage = 10
local BulletSpeed = 150
local agroDist = 100

while wait(fireRate) do
	
	--Find the target, detect if realistic to shoot
	local target = nil
	for i,v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local Torso = v:FindFirstChild("Torso")
		if human and Torso and human.Health > 0 then
			if (Torso.Position - Turret.Position).Magnitude < agroDist then
				local BulletRay = Ray.new(Turret.Position, (Torso.Position - Turret.Position).Unit * 500)
				local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(BulletRay, {Turret})
				if hit == Torso then
					target = Torso
				else
					print("Object detected")
				end
			end
		end
	end
	
	if target then
		--turn the turret to target
		local Torso = target
		Turret.CFrame = CFrame.new(Turret.Position, Torso.Position )
		
		local newBullet = Bullet:Clone()
		newBullet.Position = Turret.Position
		newBullet.Parent = game.Workspace
		newBullet.Velocity = Turret.CFrame.LookVector * BulletSpeed
		
		newBullet.Touched:Connect(function(objectHit)
			local human = objectHit.Parent:FindFirstChild("Humanoid")
			if human then
				human:TakeDamage(BulletDamage)
			end
		end)
	end
end

basically I made a turrent that will shoot a player, the turrent will stop shooting if the player was hiding at the wall but in this case the turrent wont shoot even if I move the walls