Teleport players who touch a part to a private server

  1. I make a game like doors and i want to make a server system.
    image
    If they go into an elevator anyone can join them while they are in a game, i dont need it to be like that.

  2. I need players who enter the same elevator to be teleported into the same game and so nobody could join them. For now they do get teleported but anyone can join them if they get teleported too. That makes a mess.

local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (11873076445)
--replace this part
local canTeleport = true

local function otherGame(otherPart)

 local player = game.Players:FindFirstChild(otherPart.Parent.Name)

 if player and canTeleport then

  canTeleport = false

  TeleportService:Teleport(placeID, player)

  wait(0.01) --cooldown time

  canTeleport = true

 end

end

telePart.Touched:Connect(otherGame)


I’m sure there is a function with TeleportService which is TeleportToPrivateServer that will let you do this.

Hi👋,

You’ll need to use FireServer() & OnServerEvent()

Adding a bit more onto our LocalScript

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)

And our Server Script inside ServerScriptService

local TS = game:GetService("TeleportService")
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

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

    TS:TeleportToPrivateServer(0, code, {Players})
end)

I hope i helped! :sweat_smile:
I did this on my phone so i don’t think it will work.

Anyways, goodluck! :four_leaf_clover:

1 Like

Yeah youre right it dint work. Do you know how to fix thr code?

  1. Your players table is useless the way you have put it on the client.
  2. This will result in event spam if there are multiple players.

Sorry I could not go into more detail, but like you I am on my phone and do not enjoy typing on a mobile keyboard.

1 Like

can you please suggest me some solutions when you get to your computer?