Hello, I am actually doing a game similary to Camping. In my game, there is two place: LobbyServer and GameServer. So, I try to teleport players from the LobbyServer to GameServer. In the LobbyServer, there is a boolvalue called Playing which is false whena player connect. When he touch the part, the value is true and every 60 seconds it teleport players who have their Playing value true. But I really don't know how to teleport players when their Playing value is true to a private server. I use TeleportToPrivateServer and ReserveServer. Yes, I try on the game and not on the roblox studio simulation... So thanks for answer ! :D
What you could do is have a for loop in a local script.
When using for loops you can use them to iterate over tables, and game.Players:GetChildren() is counted as a table, so you can do something like this:
local TeleportService = game:GetService("TeleportService") local pv = game.Players:GetChildren() local code = TeleportService:ReserveServer(game.[Insert Place ID]) while true do wait(60) for i = 1, #pv do local value = pv[i] if value.[Insert location of Playing value].Value == true then TeleportService:TeleportToPrivateServer(game.[Insert Place ID],code,value) end end
Value is the parameter for what player it's currently looking at.
Then put this inside the script in the part you want people to touch:
local function debounce(func) --Makes touch events not fire more then once per person local isRunning = false return function(...) if not isRunning then isRunning = true func(...) isRunning = false end end end script.Parent.Touched:Connect(debounce(function(part) local Humanoid = part.Parent:FindFirstChild("Humanoid") if Humanoid then local player = game.Players:GetPlayerFromCharacter(part.Parent) player.[Insert location of player value].Value = true end end))
Then when the player teleport script runs in 60 seconds it will teleport anyone that has their playing value set to true.
Let me know if you have any questions.
To players teleport between places create a part that you want to player touch it and get teleported and insert a script
script.Parent.Touched:Connect(function(player) if player.Parent:FindFirstChild("HumanoidRootPart") then local service = game:GetService("TeleportService"); local place = 20279777; --Put the map id that you want to players get teleported local plr = game.Players:GetPlayerFromCharacter(player.Parent) service:Teleport(place,plr); end end)