Need help with a multiplayer system

Hello! im making this post for help with a multiplayer system for my game.
I just need to find out how to make the room codes not look like “UoLVDR5KAoeihDlPkV_zH7b3cOBITZBCt18eOLyyEetMUQNLAgAAAA2” (A normal Reserved server key) as its way to long and will often tag making it really hard to share with people without a 3rd party application or something.
Is there any way to shorten the the Reserved server code thing?
idk like compress and uncompress it somehow ¯\_(·-·)_/¯

ive tried looking up solutions but all of them confuse the hell out of me

1 Like

You can create a script which will generate your own custom code, save it using a datastore. You can retrieve it later when a player wants to join this multiplier room.

Example Script
local DataStoreService = game:GetService("DataStoreService")
local ReservedData = DataStoreService:GetDataStore("ReservedServers_Data1")
local TeleportService = game:GetService("TeleportService")

local function generateCode(length)
	local characters = {"a","b","c","9","3","8","5","d","e","f","x","m","p","z","o"}
	local charItems = #characters
	for i = 1, charItems, 1 do
		characters[#characters + 1] = characters[i]:upper()
	end
	local genSequence = ""
	for i = 1, length, 1 do
		genSequence = genSequence .. characters[math.random(1,#characters)]
	end
	return genSequence
end

local function saveCode(code)
	local Success = pcall(function()
		local RobloxCode = TeleportService:ReserveServer(game.PlaceId)
		ReservedData:SetAsync(code, RobloxCode)
	end)
	return Success
end

local function getCode(code)
	local Success, robloxCode = pcall(function()
		return ReservedData:GetAsync(code)
	end)
	if Success and robloxCode then
		return robloxCode
	end
end

local function deleteCode(code)
	local Success = pcall(function()
		ReservedData:RemoveAsync(code)
	end)
	return Success
end

--[[
HOW TO USE:

--Creating Codes--
local myServerCode = generateCode(7) -- any length
saveCode(myServerCode)

--Retrieving the Roblox code by short code & teleporting the players--
local robloxCode = getCode("abcd123")

TeleportService:TeleportToPrivateServer(game.PlaceId, robloxCode, {Player1, Player2})

]]

Features:

  • Save Code
  • Get Code
  • Delete Code

If you forget to delete the code, then it will still be saved in the DataStore, but there are many options to fix that, one being to delete the code when the host (or player) leaves.

1 Like

worked like a charm, only took a little while to set up and get working with what i already had of the system! TYSM!