Gun Shooting Post-Recoil

As seen in this video the ray is being casted after the recoil and not before.


local script:

local params = RaycastParams.new()
params.FilterDescendantsInstances = {char, viewModel}
local recoilInfo = TweenInfo.new(0.05,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,0,false,0)
local function recoil()
	local randY = math.random(-0.3,0.3)
	local randZ = math.random(-0.3,0.3)

	local tweenProperties = {CFrame = cam.CFrame * CFrame.Angles(0.1,math.rad(randY), math.rad(randZ))}
	local recoilTween = ts:Create(cam,recoilInfo,tweenProperties):Play()
end
local recoilCoro = coroutine.create(recoil)
coroutine.resume(recoilCoro)


local function shoot()
	local ray = Ray.new(cam.CFrame.Position, cam.CFrame.LookVector*300)
	local hit = workspace:Raycast(ray.Origin,ray.Direction, params)
	if hit then
		shot:FireServer(hit.Instance, hit.Position, hit.Normal)
	else
		print('miss')
	end
	if zoomed == true then
		zoomShootAnim:Play(0,5,1.8)
		zoomShootAnim.Stopped:Connect(function()
			zoomIdleAnim.TimePosition = 0
		end)
	else
		shootAnim:Play(0,5,1)
	end
	recoil()
	emitter.ShellEmitter.Attachment.ParticleEmitter:Emit(1)
	shootSound:Play()
	for	i,v in emitter:GetChildren() do
		if v:IsA('ParticleEmitter') then
			v:Emit(60)
		elseif v:IsA('PointLight') then
			v.Enabled = true
			task.wait(0.15)
			v.Enabled = false
		end
	end
	shootAnim.Stopped:Connect(function()
		idleAnim.TimePosition = 0
	end)
end