How I Can Fix Turret Bullet [Not Solved]

How I Can Fix Turret Bullet
When Its Fire Its Goes To Different Positions
Video:-

Code:-

local Turrent = script.Parent
local base = Turrent:WaitForChild("Base")
local turret  = Turrent:WaitForChild("Turret")
local shootPart = turret:WaitForChild("ShootPart")
local SSound = script:WaitForChild("Sound")
local isCooldown = false
local timePerBullet = 1
local bulletDistance = 500
local maxDistance = 50
local maxAmmo = 50
local currentAmmo = maxAmmo
local Players = game.Players

while wait() do
	if isCooldown then return end	
	local charAttacking
	for i, plr in pairs(Players:GetPlayers()) do	
		local char = plr.Character	
		if char and char:FindFirstChild("Humanoid") then		
			if not charAttacking then charAttacking = char end		
			if (shootPart.Position - char.HumanoidRootPart.Position).Magnitude < (shootPart.Position - charAttacking.HumanoidRootPart.Position).Magnitude then charAttacking = char end
		end
	end
	if charAttacking and (shootPart.Position - charAttacking.HumanoidRootPart.Position).Magnitude <= maxDistance and charAttacking.Humanoid.Health > 0 then	
		if currentAmmo > 0 then		
			isCooldown = true
			currentAmmo = currentAmmo - 1		
			SSound:Play()				
			local newCFrame = CFrame.new(turret.PrimaryPart.Position, charAttacking.HumanoidRootPart.CFrame.Position)
			turret:SetPrimaryPartCFrame(newCFrame)		
			local ray = Ray.new(shootPart.Position, shootPart.CFrame.LookVector * bulletDistance)	
			local part, position = workspace:FindPartOnRay(ray, Turrent)
			if part and part.Parent:FindFirstChild("Humanoid") then
				part.Parent.Humanoid:TakeDamage(5)
			end
			local TweenService = game:GetService("TweenService")
			local bullet = script.bullet
			local Model = bullet:Clone()
			Model.Parent = workspace
			local PrimaryPart = Model.PrimaryPart
			local TravelSpeed = 20
			function Travel(Destination)
				local goal = {}
				goal.CFrame = Destination
				local tweenInfo = TweenInfo.new(TravelSpeed)
				local tween = TweenService:Create(PrimaryPart, tweenInfo, goal)
				tween:Play()
			end
			Travel(CFrame.new(Vector3.new(0.05, 0.05, (shootPart.Position - shootPart.CFrame.LookVector * bulletDistance).Magnitude)))
			game.Debris:AddItem(Model, 2)
			wait(timePerBullet)	
			isCooldown = false
		end
	end
end

Screenshot 2022-09-14 180753

File:-
Turrent.rbxl (154.2 KB)

i suggest you use fastcast instead of trying to do it. fastcast will do that all for you

https://devforum.roblox.com/t/making-a-combat-game-with-ranged-weapons-fastcast-may-be-the-module-for-you