Shoot projectile at a moving target while projectile's speed is constant

I’m making a game where AI control ships and shoot each other but when trying to shoot a target which is moving at a constant speed it always misses.

script.Parent.AlignOrientation.CFrame = CFrame.lookAt(script.Parent.Center.WorldPosition,target.Center.WorldPosition+target.AssemblyLinearVelocity*(min_dist/256),script.Parent.CFrame.UpVector)
if reload <= 0 then
	reload += 0.25
	local laser = game.ServerStorage.Laser:Clone()
	laser.CFrame = script.Parent.Laser.WorldCFrame
	laser.Damage.Value = (script.Parent.Shield.MaxValue+script.Parent.Hull.MaxValue)/40
	laser.Owner.Value = script.Parent
	laser.Parent = workspace
end

min_dist is distance from ship to target. Gravity in workspace is set to 0.

You need to do math here.

So, it always misses because it is shooting where is the target right now.

I suggest that you should get the target velocity and then do math that calculates the position it will be in 2 or how many seconds. This only works if the target’s future path is interrupted by its movement.

this code is adding velocity of the object multiplied by distance divided by projectile speed to object position. it is trying to shoot at target’s future position. but its not working

You’re not setting the laser CFrame to the AlignOrientation CFrame

if you are about the script.Parent.Laser.WorldCFrame, its just an attachment i use for shooting

Where is the part where the laser shoots? Does it not get set to AlignOrientation.CFrame?