Generating random code

My game has multiple places, so private servers just dont work (well they do, only for the lobby place, which is pretty useless since everything in the lobby is local anyway)

I wanted to make a private server system myself, and I know how to do everything except codes.
I want to make a script that generates a random unique code (5 characters) that you can use to join private servers.

I know HttpService:GenerateGUID() exists, but its way too long for you to remember.
I had an idea to make the code the first character of the 5 groups in a UUID, but the chances that a duplicate code would be generater are much bigger.

Would my idea be effective, or do I need to make a completely custom generator? If I do need a custom one, how do I do it?

2 Likes

Use Datastore To Store The Code (5 Characters)
And Maybe Use math.random(1,9) -- Four Times

Use MessagingService To Show Updated List/Servers

And Store Within The Code The UserId of the Player To Know Who Is The Owner!
It’s Should Be Somthing Like That!

:slight_smile:

Depends on what character set you want to use, either you use math.random() including the number of characters you want to include to the code OR split the string of the HttpService:GenerateGUID(false). Duplicates results in retries.

1 Like