So i was making my first raycast turret using a tutorial and i made the script But the script dosent spawn the bullet when im standing next to it. Here's the script:
--Basics local ReplicatedStorage = game.ReplicatedStorage local Bullet = game.ReplicatedStorage:WaitForChild("Bullet") --Instances local Turret = script.Parent --Gun Properties local FireRate = 0.5 local BulletDamage = 25 local BulletSpeed = 150 local AggroDist = 150 --Gun Functions while wait(FireRate) do --Find Da Target 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 < AggroDist then target = torso end end end if target then local torso = target Turret.CFrame = CFrame.new(Turret.Position,torso.Position) local newBullet = Bullet:Clone() newBullet.Position = Turret.Position newBullet.Parent = game.Workspace local Velocity = Instance.new("BodyVelocity",newBullet) Velocity.Velocity = Turret.CFrame.LookVector * BulletSpeed newBullet.Touched:Connect(function(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then human:TakeDamage(BulletDamage) end end) end end