Shorten Server UUID

A game I’m trying to make utilizes a system where players are put into a lobby while waiting for players; a pretty common practice. I want to make it to where friends can join each others’ lobbies by sharing codes with each other but UUIDs like adddda7e-2ee7-447e-a732-e0647f5a06f2 are impractical. I was wondering if there was a way to shorten these to a state where they can easily be translated back. I know I could use a system where there’s a button to join any online friends, but sometimes people just want a little bit of time away from their friends.

maybe try using string.sub (string.sub(UUID, NUMBER_TO_START, NUMBER_TO_END))

1 Like

Could you explain a little bit more? Sorry, I’m not used to modifying strings like this

You can generate a random string of say 6 characters and store that as a key in a data store. The value would be the server’s UUID.

2 Likes

Imagine if you wanted to short your UUID to let’s say only 6 numbers, you would just do string.sub(UUID_HERE, 1, 6) that would make the UUID only 6 characters long.

By doing so, the UUID would no longer be unique, and the chance of collision raises dramatically with the number of servers open.

Then do checks for it to make sure the UUID wouldn’t be the same

That sort of defeats the purpose of using a UUID in the first place, doesn’t it? If that is that case, then I’d rather go with @ProbableAI 's response above instead of yours.

1 Like

Yeah but who needs something so unique with like 36 characters

It is better to make it to 6 characters and just check if the UUID isn’t used

The purpose of having a UUID in the first place is to guarantee (near) unique identifiers without having to validate their uniqueness in the first place. Again, your solution would work in the short term, but is impractical for the use case proposed by OP.

1 Like

You can achieve this by using string.sub.
The syntax is as follows: string.sub(String, Start Number, End Number)

Let’s say the ID variable is called UUID and it stores 8fdc0b90-8373-11eb-8dcd.
If you wanted between 1-6 it would look something like: string.sub(UUID, 1, 6)
Which will return: 8fdc0b

Many people here have suggested using string.sub to get a portion of the UUID, but you could try using string.pack instead to compress it. Players can share the compressed ID, and you can uncompress in the script.

Sorry for the delay!
I’ve noticed that it has a few arguments that I’m not quite sure about and LUA manuals haven’t been all that helpful.