Script dont see reserve server. Do I need to use bindable event?

local teleportService = game:GetService("TeleportService")

local InvokeCr = game.ReplicatedStorage.CreateServer
local InvokeJo = game.ReplicatedStorage.JoinServer

script.Parent.PlaySolo.MouseButton1Click:Connect(function()
	local InvokeServerC = InvokeCr:InvokeServer()
	local Place = teleportService:ReserveServer(18444133431)
	teleportService:TeleportToPrivateServer(18444133431,Place,{game.Players.LocalPlayer})
end)

script.Parent.Multyplayer.TextBox.FocusLost:Connect(function(Entered,input)
	if not Entered then return end
	local enteredCode = input:lower()
	local InvokeServerJ = InvokeJo:InvokeServer(enteredCode)
	if InvokeServerJ then
		teleportService:TeleportToPrivateServer(18444133431,Place,{game.Players.LocalPlayer}) -- sctipt dont know what is "Place"
	else
		script.Parent.Multyplayer.TextBox.Text = "Invalid Code"
	end
end)

problemm is writed in the code in comment

TeleportService | Documentation - Roblox Creator Hub You should be using this instead of TeleportToPrivateServer, and you should be using a server script for player teleportation rather then a local script.

1 Like

Can you explain why I should use Async instead of ReserveServer? How will this help me? And about using teleportservice on the server, why is it important?

You should be using TeleportAsync rather then TeleportToPrivateServer as its can do more then the separate functions, looks nicer, and is actively recommended to be used over the older functions.

The server should be handling teleportations as TeleportService is meant to be used on the server to teleport players rather then locally to avoid issues between the client and the server

1 Like

I rewrote my script to the server, as you said. But still, how can I fix the error that the server does not know what a reserved place is when a player tries to join?

local MemoryStoreService = game:GetService("MemoryStoreService")
local gameQueue = MemoryStoreService:GetQueue("ActiveGameCodes", 100)
local teleportService = game:GetService("TeleportService")

local min_letter, max_letter = ("a"):byte(), ("z"):byte()
local min_number, max_number = ("0"):byte(), ("9"):byte()

local function generateRandomString(length)
	local result = ""
	for i = 1, length do
		if math.random() < 0.5 then
			result = result .. string.char(math.random(min_letter, max_letter))
		else
			result = result .. string.char(math.random(min_number, max_number))
		end
	end
	print(result)
	return result
end

game.Players.PlayerAdded:Connect(function(plr)
	
	local Uis = plr.PlayerGui.Menu
	local PlaySolo = Uis.PlaySolo
	local Multiplayer =  Uis.Multyplayer.TextBox

	PlaySolo.MouseButton1Click:Connect(function()
		local randomString = generateRandomString(8)
		gameQueue:AddAsync(randomString, 1800) 
		local Place = teleportService:ReserveServer(18444133431)
		teleportService:TeleportToPrivateServer(18444133431,Place,{plr},nil,{TeleportData = randomString})
	end)

	Multiplayer.FocusLost:Connect(function(Entered,input)
		if not Entered then return end
		local enteredCode = tostring(input):lower()
		
		local success, result = pcall(function()
			return gameQueue:ReadAsync(1)
		end)
		if success and result == enteredCode then
			teleportService:TeleportToPrivateServer(18444133431,Place,{plr},nil,{TeleportData = result}) -- heres issue
		end
	end)
end)
local TeleportService = game:GetService("TeleportService")

game.Players.PlayerAdded:Connect(function(player)
	task.spawn(function()
		wait(5)
		local reserveServer = TeleportService:ReserveServer(game.PlaceId)
		local teleportOptions = Instance.new("TeleportOptions")
		teleportOptions.ReservedServerAccessCode = reserveServer
		TeleportService:TeleportAsync(game.PlaceId, {player}, teleportOptions)
	end)
end)

This is a working example with TeleportAsync()

We create the reserve server, then create the teleportOptions, set the ReservedServerAccessCode of the teleport options to send the player to that reserved server, then use TeleportAsync()

(I was also able to get it to work with TeleportToPrivateServer)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.