How can I run ReserveServer in the Client?

Hello Developers! I am trying to run .ReserveServer() in the Client.

Here is what I tried:

script.Parent.MouseButton1Down:Connect(function(plr)
	local TS = game:GetService("TeleportService")
	local Players = game:GetService("Players")
	local placeId = 5738403458
	local code = TS:ReserveServer(5738403458)
	local plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
	TS:TeleportToPrivateServer(5738403458, code, plr)
end)

When I try it:
image
It doesn’t work. This is inside a ServerScript inside of a TextButton.

When I click HTTP 403 (Forbidden)
local code = TS:ReserveServer(5738403458) is what it sources to.

If you can help, please let me know thx, WE!

1 Like

Is there a reason it needs to be in the client? And why plr is script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent instead of just using LocalPlayer?

1 Like

This is a ServerScript. You cannot use ReserveServer inside of the Client.

So use a remote event for this?

1 Like

Uhh… Ok…
image
I forgot to mention Time Trials… Even more…

You got a lot of refactoring to do.

1 Like

I went to the place and it shows up as private which might be causing your error. Making the place public might solve this.

It is public to all Group Members, and there are other ReserveServers that work inside of the Server. Here is a little snippet:

TeleportService:TeleportToPrivateServer(PlaceID, reservedServer, join)

You should not be listening for UI events in a server script. It will not work on a live server with filtering enabled. You should instead use a RemoteEvent or RemoteFunction that is called by a LocalScript and calls a server script that will reservice the server.

Ok. Would it be possible to use only one?

Yes. In your case, a RemoteEvent works fine because you don’t need to return anything to the client.

So, you will have the server define the OnServerEvent for the remote event. That callback will be firewhen your client script calls FireServer on the RemoteFunction after the button is pressed.

Server:

MyRemoteEvent.OnServerEvent:Connect(function(Player, id)
    local TS = game:GetService("TeleportService")
    local code = TS:ReserveServer(id)
    TS:TeleportToPrivateServer(id, code, Player)
end)

Client

MyRemoteEvent:FireServer(5738403458)

Im talking about only using a single event because I would have a lot of maps to redirect to.
image

TeleportService is not designed to work in studio and will most likely fail when used in it.

Note on the DevHub

I tried running similar code in studio and I get a similar error however only while in studio. Publishing your game and playing it from the client should work.

image

I know about that. When I try to teleport using ReserveServer in the real game, it gives the 403 error. What I am trying to do is run a single remote event to teleport a player to the level/map they desire.

Ah, yes. You can pass an argument to the event with the place that you want the server to teleport you to. I updated my example with an argument.

I am getting this:
image
Client:

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage"):WaitForChild("TeleportReserve"):FireServer(5738403458)
end)

Server:

game:GetService("ReplicatedStorage"):WaitForChild("TeleportReserve").OnServerEvent:Connect(function(Player, id)
	local TS = game:GetService("TeleportService")
	local code = TS:ReserveServer(id)
	TS:TeleportToPrivateServer(id, code, Player)
end)

nvm. I got it to work:
Server:

local TS = game:GetService("TeleportService")
local code

game:GetService("ReplicatedStorage"):WaitForChild("TeleportReserve").OnServerEvent:Connect(function(Player, id)
	code = TS:ReserveServer(id)
	local players = {}
	table.insert(players, Player)
	TS:TeleportToPrivateServer(id, code, players)
end)

What we had to do is define a table for the players. That is what we had to do all along. Since this uses your code @TheNickmaster21, I will mark the original reply as solution.

1 Like

I thought to service only works in real game.

We were trying it in a real game. I do know that you cannot teleport in Studio.

1 Like

If it isn’t working in the game it probably is because you didn’t enable it in Studio Settings. You gotta enable stuff like being able to teleport to third parties in the settings for the teleportation to work.