Teleporting players to a private server

You can write your topic however you want, but you need to answer these questions:

  1. I need players who touch a part to be teleported to a private server but this code does nothing…

Any suggestions?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
        local PlrTable = {} 
        table.insert(PlrTable, hit.Parent.Name)
	Event:FireServer(PlrTable)
end
end)
1 Like

First of all, what is the server code for the remote event?

Edit : You should probably be doing the touched event on the server by the way.

local TS = game:GetService(“TeleportService”)
local Event = Instance.new(“RemoteEvent”, game:GetService(“ReplicatedStorage”))
Event.Name = “TeprtEvent”

Event.OnServerEvent:Connect(function(Players)
local code = TS:ReserveServer(11873076445)

TS:TeleportToPrivateServer(11873076445, code, {Players})

end)

Ok, you should definitely be doing this on the server because an exploiter could easily fire that remote event and give a table that includes all the players. And local scripts don’t run on workspace.

You also can’t use teleport service in studio, you will have to play test it in actual Roblox.

-- server script in ServerScriptService

local TS = game:GetService("TeleportService")
local Part = workspace.Part

Part.Touched:Connect(function(otherPart)
    if otherPart.Parent:FindFirstChildWhichIsA("Humanoid") then
        local success,err = pcall(function() -- to get the error incase it does error
            local code = TS:ReserveServer(game.PlaceId)
            local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent)

            TS:TeleportToPrivateServer(game.PlaceId,code,{ plr })
        end)

        if not success then -- it errored, print the error
            warn("Could not teleport " .. otherPart.Parent.Name .. "! Error : " .. err)
        end
    end
end)
2 Likes

Thanks! can i replace game.PlaceID with a custom place id btw?

Yes, you can replace it with another game id.

1 Like

is there a way to teleport several players to the same server? I’ve tried doing that via loop but that didn’t work

Make sure you are using the same server everytime, don’t make a new server for each player. I’ve made this mistake before and it was quite hard to fix.

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