DataStores: Custom Private Servers within a Universe

OK, so what I’m planning to do in a game is that:

  • There’s a start place (lobby)
  • More games are accessible within the lobby

I’m trying to script a system where you could buy a private server for the entire game that you could set friends/select users to be part of.

Problem is, players can have 200 friends, and trying to GetAsync 200 times to check for servers would exhaust the DateStore limit.

How would I do such?

2 Likes

I think this might be useful: http://wiki.roblox.com/index.php?title=API:Class/Player/GetFriendsOnline

It only returns online friends, which may be a lot fewer

2 Likes

Friends should be able to access your private server even if they’re offline.

An alternative to what @Disgustedorito posted would be http://wiki.roblox.com/index.php?title=API:Class/Players/GetFriendsAsync

I’ve never used it, but the wiki implies that it will work for offline friends, as it returns an IsOnline boolean.

2 Likes

I think that @Iiau knows how to do this already. Iiau is having problems with the Data Stores aspect of this.

Iiau wants users to be able to set their private server to “any friends can access”. This should stay updated with the friends list of the server host and allow their friends to enter regardless of whether or not the server host is online.

It seems that the only option is the loop through up to 200 friends and make a GetAsync call for each friend to check if that friend hosts any friends-allowed server. Iiau knows how to use GetFriendsAsync. Iiau does not know how to avoid 200 GetAsync calls.

2 Likes

I can’t think of any good way to do this.


One thing you could try is budgeting requests for this purpose. Something like 20 global per-minute requests and 5 personal per-minute requests. This would let each player check at least 5 friends per minute, then the 20 global requests can be split up between all players that need to check their friends evenly.

Most players won’t have 200 friends. Those that do will have to wait at least 8 minutes, but it’s better than nothing. :man_shrugging:


An experimental option you could try is having one big global list of every friends-allowed server hosts’ userIds. This would allow you to check if any friend userIds are in the global list and only grab more server info from the data store if they are.

Whether or not this is feasible depends upon a ton of variables though…

  • How many total private servers there will be
    • You’ll probably have to split the global list up between multiple data store keys, but as long as it’s not too many, you’ll be fine.
  • How often you update the list.
    • You can’t update it too often as the data store won’t allow it
    • You can split it up between more keys if you need to update it more often, but that brings us back to our first point.
    • If you don’t update too often, then you can use OnUpdate
  • How many users you can pack into one data store value
    • You can probably pack around 20,000+ into a single value if you put the normal string representation of the number into the data store, but this is unpredictable and depends on how big the user ids are.
    • If you convert user ids to 42-bit binary numbers, then put 6 bits in each character, you can predictably fit 37142 user ids in each data store value.
  • How intensive the packing/unpacking process is
    • This probably won’t be an issue, but if you do something like the binary packing above, you might have to wait() some to keep the server from freezing momentarily.

The upside is that you should be able to do this only once per server then listen to OnUpdate. This could totally fail though, which is why I call it experimental.

Example of packing a user id into a string value

NumberToCharExample6Bit

This will use characters 64 through 127, which should be safe to use. 128-255 and 0 might cause issues in the data store, I think. This gives us 6 bits per character and 7 characters per 42-bit number.

2 Likes

It’s either that or migrate to a Http solution. Oh well, unless Roblox could make some API for it.

1 Like

HTTP is the way to go for this. I would suggest using Node.js with MongoDB hosted on Openshift.

2 Likes

I’d have to store all the data on a web endpoint then?

1 Like

Sadly, it seems so. :<

But then it gives you an excuse to make private servers cost lots of money… (shh)

1 Like

The depends on how many friend server hosts a player will have on average.

If there will be very few friend server hosts then you can use HttpService only to find friend server host user ids. Once you get the user ids, you can look up the rest of the server info using Data Stores. You can tell the external database server to add/remove a user id from hosting a friends-allowed server when they start/stop a server or change server settings.

If there will be a lot of friend server hosts, then you’ll have to store most of the server info in your external data base and grab it using HttpService.