--[[
	
	Cleaner alternative to GetNameFromUserIdAsync that caches to avoid constant yielding.
	
	Functions.UserIdToUsername(
		userId,					<-- |REQ| 	User ID
	)
	
--]]




return function(userId)
	--- Check cache
	if cachedUsernames[userId] then
		--- Return cache
		return cachedUsernames[userId]
	
	else
		--- Grab username from web
		local username
		local success = pcall(function()
			username = game.Players:GetNameFromUserIdAsync(userId)
		end)
		
		--- Failed :(
		if not success then  return  end
		
		--- Success! Updating cache
		cachedUsernames[userId] = username
		
		--
		return username
	end
end
