Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Make a players teleporter to private server ?

Asked by
mist0s 38
5 years ago
Edited 5 years ago

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

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Really thanks for an answer so fast. For the script I try that on a script and local script: local TeleportService = game:GetService("TeleportService") local pv = game.Players:GetChildren() local code = TeleportService:ReserveServer(2675486660) while true do wait(60) for i = 1, #pv do local value = pv[i] if value.FindFirstChild("Settings").Playing.Value == true then mist0s 38 — 5y
0
TeleportService:TeleportToPrivateServer(3154696827,code,value) end end end (the end of the comment) mist0s 38 — 5y
0
But it doesn't work, why ?? mist0s 38 — 5y
View all comments (2 more)
0
Did you add the regular script inside the part that you want people to touch? Babyseal1015 56 — 5y
0
Also in the local script, it will need to be in starter player scripts, and on the while true do statement it needs an extra end I forgot to add that. And then ReserveServer() and TeleportToServer() both need to have the Id of the place that you want to teleport the players to. Babyseal1015 56 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

Answer this question