Projectile effect delay issue

When I shoot a projectile which is a part with a trail, it originates in the barrel of a viewmodel and uses a renderstepped loop to move it forward.
The issue I have is that when you fire projectiles in quick succession, it seems that they are being delayed and originating a few studs from the barrel. This effect seems to scale with speed of the bullet.
Below is a video of the issue and the function that is called when a projectile is fired.
If anyone can explain why this is that would be great!

mainModule.ClientProjectile = function(realCFrame, aestheticCFrame, destination,velocity, gun)
	
	local diccctionary = {}
	
	local projectile = RS.bullet:Clone()
	projectile.Parent = game.Workspace
	projectile.Size = Vector3.new(.1,.1,1)
	projectile.CFrame = aestheticCFrame


	local projectileStartVector = projectile.Position
	local MovementLoop
	local hitCheck = false

	local previousRayCFrame
	local rayCFrame = realCFrame


	local distance = (destination - realCFrame.Position).Magnitude
	local time = distance / velocity

	local distance2 = (destination - aestheticCFrame.Position).Magnitude
	local velocity2 = distance2 / time
	
	
	local framed = 0
	MovementLoop = game:GetService("RunService").Heartbeat:Connect(function()
		framed +=1

		
		--[[]]
		
		--print((projectile.Position - aestheticCFrame.Position).Magnitude .. " frame:  " .. (frame) .. " number: " )
		
		diccctionary[framed]= {
			frem = framed,
			distancey = (projectile.Position - aestheticCFrame.Position).Magnitude
		}
		
		
		previousRayCFrame = rayCFrame
		projectile.CFrame *= CFrame.new(0, 0, -velocity2 )
		rayCFrame *= CFrame.new(0,0, -velocity)

		local collisionCheck = workspace:Raycast(previousRayCFrame.Position, rayCFrame.Position - previousRayCFrame.Position)


		if collisionCheck and hitCheck == false  then

			local objectHit = collisionCheck.Instance
			local plrHit = game.Players:GetPlayerFromCharacter(objectHit.Parent)
			hitCheck = true
			print(collisionCheck.Instance)
			projectile:Destroy()
			MovementLoop:Disconnect()
		
			mainModule.HitEffect(collisionCheck.Position , collisionCheck.Normal)
		end
		
		if (projectile.Position - projectileStartVector).Magnitude >= 100 then
			projectile:Destroy()
			MovementLoop:Disconnect()
		end

	end)
	
	gun.GunComponents.Barrel.MuzzleEffect:Emit(1)
	
	
end

Boosting topic

characters +++++

Without knowing what the arguments that are being passed to this function are, I cant give an answer. But looking over I noticed a flaw that while calculating the distance that the ray needs to travel, you subtract “destination” from realCFrame and aestheticCFrame. assuming that these two CFrames are different, their magnitudes will not be equal and cause one of them to travel less distance than the other.

RealCFrame is the player’s HRP, which the “real” projectile that does calculations originates from, and aestheticCFrame is a guns barrel where a “fake” projectile originates from. The point of the calculations is to account for the position difference between the 2 CFrames to insure that both projectiles hit the destination at the same time.

Besides telling you check if aestheticCFrame and velocity is what you want to be, I can’t see you much wrong, just be sure to calculate realCFrame and aestheticCFrame seperately with their own seperate values, because lines:

local distance = (destination - realCFrame.Position).Magnitude
local distance2 = (destination - aestheticCFrame.Position).Magnitude

are actually are calculated like this

because of this, the aesthetic bullet will travel faster than the real one, because it is angled.