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:
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.
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?
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.
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)
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.
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.
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.
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.