Simple Private Server Joining System with a code? - Scripting Help

Hi, can somebody whip up a code for me really quick, for a private server system:

This is what I have rn, ik it doesn’t work, I’m very lost.

local ts = game:GetService("TeleportService")

game:GetService("ReplicatedStorage").StartPrivateGame.OnServerEvent:Connect(function(player, code1, placeid)
	local TS = game:GetService("TeleportService")
	local Players = game:GetService("Players")

	local code = TS:ReserveServer(game.PlaceId) -- Returns a code


game:GetService("ReplicatedStorage").JoinPrivateGame.OnServerEvent:Connect(function(player, code1, placeid)
	if code1 then
		ts:TeleportToPlaceInstance(placeid, code1, player)

Btw, code1 is a random number generated,

1 Like

Is code1 a valid JobId? You say it’s a randomly generated number, can you clarify if you’re just generating a number randomly or is it an actual JobId of an opened server? Also providing any errors would be really helpful!

It’s just a random number, can you make it so that it’s a JobId of an opened server? Like, the idea is that You make a server with the click of a button, and when you enter that server, a small 6 - 8 digit code appears on the bottom right of the screen. You tell that code to a friend and in the ‘main game’ they enter it into a text-box and when they hit a button it teleports them to that server.

I have no idea what I’m doing. I’ve just been combining code from different teleporting Api’s, there isn’t any tutorial for this or any community things other than this: Join private server by 5-digit code - #4 by 7z99

Which didn’t really help.