here is the old code for a turret, i have the firerate, bullet damage and speed, and aggro dist sorted, i have yet to find out how to make it shoot like a shotgun or in bursts, and yes i did made this code myself
local bullet = ReplicatedStorage:WaitForChild("Bullet")
local sound = game.Workspace.Model.turret.shot
local turret = script.Parent
local fireRate = 1.5
local bulletDamage = 15
local bulletSpeed = 200
local aggroDist =50
while wait(fireRate)do
local target = nil
for i, v in pairs(game.Workspace:GetChildren())do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso") or v:FindFirstChild("UpperTorso")
if human and torso and human.health > 0 then
if (torso.Position - turret.Position).magnitude < aggroDist then
local bulletRay = Ray.new(turret.Position,(torso.position - turret.Position).unit * aggroDist)
target = torso
end
end
end
if target then
sound:Play()
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(partHit)
local human = partHit.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(bulletDamage)
newBullet:Destroy()
end
end)
end
end```