How to make a private-server-like public server?

How do I teleport someone to a public server using TeleportAsync() but also make it private without directly setting it to private? (I can’t set it directly because then other people can’t join the server , I am making a level editor)

Just kick anyone who is not permitted to play?

2 Likes

TeleportService:ReserveServer() exists.

3 Likes

Yes, but I can’t do that or atleast I don’t know how. I tried that method for literally 18 hours.
It just lets the first player in and then not the other one, here is the link to both of my other dev forum posts about this:

2 Likes

Yes I have that in the game already

1 Like

could you try to explain to me what are you trying to do…? cause i kinda dont understand what u mean by that

2 Likes

I am making a level editor in my game.
There is a gray textbox underneath the play button.
The player can input their friends name in the textbox to join them, if they’re in the level editor place.

If the player clicks play without putting anything in the textbox he gets sent to his “private server”
If the player inputs their friends name and its correct and they’re in game they get teleported to their level editor place, if they’re not in game, or aren’t their friend or aren’t online it will send them back.

Everything works. Except the teleporting part… especially where we try to join the player’s friend. It just says that access code is invalid and other times when I try different solutions it spits out different errors… I tried using a public server, thought it worked but now people get teleported to the public server even when they dont want to, and want to make their own server instead.

This is the game:

1 Like

okay, so from what i can see you’re trying to make a matchmaking system

here’s what u gotta do, first reserve a new server and make sure its a variable
local code = TS:ReserveService, then check if the textbox has text and teleport the players:

   if textbox.Text ~= "" then
      local plr = game.Players:GetPlayerByName(textbox.Text)
      if not plr then return end
      local players = {game.Players.LocalPlayer, plr}
      TS:TeleportToPrivateServer(game.PlaceId, code, players)
   end

this should be ur final code:

local code = TS:ReserveService

button.Activated:Connect(function()
  if textbox.Text ~= "" then
      local plr = game.Players:GetPlayerByName(textbox.Text)
      if not plr then return end
      local players = {game.Players.LocalPlayer, plr}
      TS:TeleportToPrivateServer(game.PlaceId, code, players)
   end
end)

2 Likes
local DataStoreService = game:GetService("DataStoreService")
local serverDataStore = DataStoreService:GetDataStore("ReservedServers")

local owner="none"

game.Players.PlayerAdded:Connect(function(player)
	if owner=="none" then
		owner=player.UserId
		local reservedServerCode=game.JobId
		if reservedServerCode then
			player:SetAttribute("ReservedServerCode", reservedServerCode)
			-- lets also update the serverDataStore with this newfound information
			serverDataStore:SetAsync(player.UserId, reservedServerCode)

			print(reservedServerCode,player:GetAttribute("ReservedServerCode"))
		else
			warn("NO 2")
		end
	else
		-- lets check if this user is friends with the owner
		if player:IsFriendsWith(owner) then
		else
			player:Kick("You're not friends with the owner of this server.")
		end
	end
end)

Screenshot_759

This is my code for the level editor place, but an error occurs. I can’t for some reason get the JobId because its a private server, so I can’t get the server access code.

Server script in main game (not editor)

local TeleportService = game:GetService("TeleportService")
local DataStoreService = game:GetService("DataStoreService")
local serverDataStore = DataStoreService:GetDataStore("ReservedServers")

game.ReplicatedStorage.tpServer.OnServerEvent:Connect(function(player,id)
	while game.Players:FindFirstChild(player.Name) do
		local success, errorMessage = pcall(function()
			-- lets get serverDataStore, and that is the serverAccessCode
			local serverAccessCode = serverDataStore:GetAsync(id) -- who we're joining

			local tpData={
				ReservedServerCode=serverAccessCode
			}
			print(serverAccessCode)
			--TeleportService:TeleportToPlaceInstance(17503907776, serverAccessCode, player, nil, tpData)
			-- lets try using TeleportAsync, instead of TeleportToPlaceInstance, while still teleporting the player to serverAccessCode
			--local tpOptions=Instance.new("TeleportOptions")
			--tpOptions.ReservedServerAccessCode=serverAccessCode
			--tpOptions.ServerInstanceId=serverAccessCode
			--tpOptions:SetTeleportData(tpData)
			--TeleportService:TeleportAsync(17503907776, {player}, tpOptions)
	
			local players = {player}
			game:GetService("TeleportService"):TeleportToPrivateServer(17503907776, serverAccessCode, players)--]]
		end)

		if success then
			print("Successfully teleported", player.Name)
		else
			warn("TeleportToPlaceInstance failed:", errorMessage)
		end
		wait(math.random(4,6))
	end
end)

Local script in main game (not editor):

if script.Parent.leveleditoroptions.TextBox.Text~="" then
			local nahs=false

			local plr = game.Players:GetUserIdFromNameAsync(script.Parent.leveleditoroptions.TextBox.Text)
			if plr then
				--[[local serverAccessCode = serverDataStore:GetAsync(plr) -- who we're joining
				
			local players = {game.Players.LocalPlayer, plr}
			game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, serverAccessCode, players)--]]
				game.ReplicatedStorage.tpServer:FireServer(game.PlaceId)
			nahs=true
			end
		
		if nahs==false then
			script.Parent.loading.Visible=false
			script.Parent.leveleditoroptions.played.Visible=true
		end
	else
		script.Parent.Frame.RemoteEvent:FireServer(3)
	end
1 Like

If u want u can ask questions btw because what im saying probably does not make sense at all.