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

ReserveServer not working, Code same as wiki?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago
Edited 3 years ago

I'm making a camping type game and I'm using Reserve server to make a new server so players can't go to the same server, I wrote the code and it doesn't work, I browsed over 50+ pages and it's still not working, Can anyone help me?

Code:

local teleportService = game:GetService("TeleportService")

local code = teleportService:ReserveServer(7140418017)

teleportService:TeleportToPrivateServer(7140418017, code, unpack(plrs)) -- getting every player in a table and teleporting them

Full Code:

local teleportService = game:GetService("TeleportService")

local code = teleportService:ReserveServer(7140418017)

local plrs = {}

local buttonPart =game.Workspace:FindFirstChild("MainLobby"):FindFirstChild("TouchParts"):FindFirstChild("TouchPart2")

local infoPart = game.Workspace:FindFirstChild("MainLobby"):FindFirstChild("InfoPart2")

local infoText = infoPart:FindFirstChild("SurfaceGui"):FindFirstChild("TextLabel")

local bus = game.Workspace:FindFirstChild("MainLobby"):FindFirstChild("Buses"):FindFirstChild("Bus2")

local teleportPart = bus:FindFirstChild("TPPart")

local cooldown = false

local timer = 30

game:GetService("Players").PlayerAdded:Connect(function(player)

    player:WaitForChild("PlayerGui"):WaitForChild("LeaveGui"):WaitForChild("LeaveButton").MouseButton1Click:Connect(function()

        player.Character:WaitForChild("Humanoid").Health -= 100

        table.remove(plrs, table.find(plrs, player))

        player:WaitForChild("PlayerGui"):WaitForChild("LeaveGui").Enabled = false

    end)

end)

buttonPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if cooldown == false then

            cooldown = true

            local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

            local char = hit.Parent

            table.insert(plrs, player)

            char:WaitForChild("HumanoidRootPart").CFrame = teleportPart.CFrame

            player:WaitForChild("PlayerGui"):WaitForChild("LeaveGui").Enabled = true

            wait(1)

            cooldown = false

        end
    end
end)

while true do

    wait()

    for i = timer,0,-1 do
        infoText.Text = "Time until leaving: "..i.." Players: "..#plrs
        wait(1)
    end

    cooldown = false

    infoText.Text = "Teleporting..."

    teleportService:TeleportToPrivateServer(7140418017, code, plrs)

    wait(10)

    cooldown = true

end

1 answer

Log in to vote
0
Answered by
7z99 203 Moderation Voter
3 years ago

:ReserveServer accepts a table of players, unpacking the table of players would return the players in a subsequent order.

You only have to pass the plrs variable, no need to unpack.

local teleportService = game:GetService("TeleportService")

local code = teleportService:ReserveServer(7140418017)

teleportService:TeleportToPrivateServer(7140418017, code, plrs)
0
Expected identifier when parsing expression, got ) MattVSNNL 620 — 3y
0
Are you sure you pasted your code exactly? I don't see any extra parentheses in my post or yours. 7z99 203 — 3y
0
Thats weird MattVSNNL 620 — 3y
0
Sorry but it didn't work MattVSNNL 620 — 3y
0
I fixed the error but it doesn't work MattVSNNL 620 — 3y
Ad

Answer this question