Creating a random code and using it to make a lobby

Hey there!

I have made a matchmaking system in the past, but it had some issues and I would like to know how to make one with a random code.

There are 2 games that I know of that use this. Bedwars, and raise a floppa. You can create your own lobby and it gives you a code that you can give to your friends.

I don’t need help with the teleporting of the player, or creating a private lobby. I need help with making a code to access that lobby, and creating that randomized code.

I’m not asking for a full script I just need help with creating and checking for the code using messaging service.

Thanks, Jail.

game.JobId is a built in property that will generate a unique code for every server, additionally, this ‘random code’ could be used directly in teleport options to teleport others to this server!

If you want a spiffier system, you would need a database that links JobId behind the scenes to a shorter, random code.

Attached is some code to generate a random string, cheers! Although unlikely, you would want to check to see if the random string is already attached to a jobid. To prevent buildup, clear this link when server is closed.

local random = Random.new()
local letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'}

function getRandomLetter()
	return letters[random:NextInteger(1,#letters)]
end

function getRandomString(length, includeCapitals)
	local length = length or 10
	local str = ''
	for i=1,length do
		local randomLetter = getRandomLetter()
		if includeCapitals and random:NextNumber() > .5 then
			randomLetter = string.upper(randomLetter)
		end
		str = str .. randomLetter
	end
	return str
end

print(getRandomString(7, true))

Also, don’t use messaging service. Use the newly created MemoryStoreService! The wikipage should clear up any confusion and make it’s application clear!

Oh cool, an amazing new service!