Creating unique server codes

I am making a custom server system with MemoryStoreService, the only problem I have now is that I don’t know how to make unique server invite codes. I don’t want to check if the code is already taken.

I tried using code returned by TeleportService:ReserveServer before the first dash sign, but I’m not sure if it will always be unique.

image

Another idea I had was to use DateTime.now. I wanted to truncate it to only 8 numbers so it would look like 77465979 instead of 1650977465979.

Not quite 8 digits, but this could work:
https://developer.roblox.com/en-us/api-reference/function/HttpService/GenerateGUID

Alternatively, check out this post:

I forgot to mention that the code will be used for inviting other players.
Servers will only last for 24 hours in the MemoryStoreService sorted map, so maybe the DateTime.now method would work?

image

And the access code (generated by TeleportService:ReserveServer) is used to teleport to the server.

image