Help with turning this into ApplyImpulse

I have an NPC that shoots a projectile with a loop and I want to change this into ApplyImpuse so it can reduce lag. How can I achieve this?


Remote.Event:Connect(function(firePoint, hitPosition)
	local g =,-100,0) -- gravity
	local x0 = firePoint.WorldPosition -- position to shoot
	local t = 1 -- time to destination

	local v0 = (hitPosition - x0 - 0.5*g*t*t)/t

	local projectile ="Part")
	projectile.CanCollide = false
	projectile.Parent = HeroAbilitiesFolder

	local nt = 0

	local connection = RunService.Heartbeat:Connect(function()
		projectile.CFrame =*g*nt*nt + v0*nt + x0, projectile.PrimaryPart.AssemblyLinearVelocity + projectile.PrimaryPart.Position)
		nt = nt + RunService.Heartbeat:Wait()

Instead of a while/ApplyImpulse script you probably want to use a LinearVelocity constraint.