FastCast issue - CastTerminating causing issues

I need to use the CastTerminating event to dispose of the cosmetic bullets when they reach the max distance, however, when I do so, LengthChanged and RayHit breaks.

Without CastTerminating:

With CastTerminating:

Code:


local function OnLengthChanged(ActiveCast, LastPoint : Vector3, RayDirection : Vector3, Displacement : number, SegmentVelocity : Vector3, BulletObject : BasePart?)
	if BulletObject then
		local Length = BulletObject.Size.Z/2
		local Origin = MuzzleValue.Value.WorldPosition
		local GoalCF = nil :: CFrame?
		
		task.spawn(SetFX, true, BulletObject)
		
		if FrameTable[BulletObject] ~= nil then
			if FrameTable[BulletObject] >= INITIAL_FRAME_COUNT then
				GoalCF = CFrame.lookAt(LastPoint, LastPoint + RayDirection) * CFrame.new(0, 0, -(Displacement/2 - Length))
			else
				GoalCF = CFrame.lookAt(Origin, Origin + RayDirection)
			end
		else
			FrameTable[BulletObject] = 0
			GoalCF = CFrame.lookAt(Origin, Origin + RayDirection)
		end

		FrameTable[BulletObject] += 1 :: any
		workspace:BulkMoveTo({BulletObject :: Instance}, {GoalCF}, Enum.BulkMoveMode.FireCFrameChanged)
	end
end

local function OnRayHit(ActiveCast, RaycastResult : RaycastResult, SegmentVelocity : Vector3, Bullet : BasePart?)
	local Hit : Instance? = RaycastResult.Instance

	if Bullet and FrameTable[Bullet] and FrameTable[Bullet] <= INITIAL_FRAME_COUNT then
		local Direction = RaycastResult.Position - Bullet.Position
		local OriginalPosition = Bullet.Position

		task.spawn(function()
			task.wait()
			Bullet.CFrame = Bullet.CFrame + Direction * 0.5
			
			task.wait()
			Bullet.CFrame = Bullet.CFrame + Direction * 0.5
		end)
	end

	task.delay(2, function()
		if Bullet and FrameTable[Bullet] then
			FrameTable[Bullet] = nil
		end

		if Bullet then
			SetFX(false, Bullet)
			PartProvider:ReturnPart(Bullet)
		end
	end)
end

local function OnCastTerminating(ActiveCast)
	local Bullet = ActiveCast.RayInfo.CosmeticBulletObject :: BasePart?
	
	if Bullet then
		SetFX(false, Bullet)
		PartProvider:ReturnPart(Bullet)
	end
end