Hi there!
I made a menu system and I want it so that when the “button” is pressed it will teleport the player to a reserve server. the menu is perfectly functioning and the reserve works but not when used so that when the player clicks the button it will function.
The reserve is being called from a script in StartGui as well as the click.
code:
local ReserveButton1 = game.StarterGui.ScreenGui.PlayFrame.GameTypeButton1
local function TeleportToReserve1(player)
print("working")
local TPS = game:GetService("TeleportService") -- We get teleport service
local AccessCode = TPS:ReserveServer(10851208543) -- Inside here, you put the ID of the game you want to create a server for.
local CustomLoadingScreen = game.ReplicatedStorage.TeleportGui
local PlayerTable = {} -- Make a table for players
for _, player in pairs(game.Players:GetPlayers()) do
table.insert(PlayerTable, player) -- For each player, we'll insert them into the table.
end
TPS:TeleportToPrivateServer(10851208543, AccessCode, PlayerTable, CustomLoadingScreen) -- We teleport all the players at the same time by teleporting the table that they are in.
end
ReserveButton1.MouseButton1Click:Connect(TeleportToReserve1)
Any help is appreciated thank you !!
Edit:
local ReserveButtonOne = game.StarterGui.ScreenGui.PlayFrame.GameTypeButton1
local function TeleportToReserve1(player)
print("working")
local TPS = game:GetService("TeleportService") -- We get teleport service
local AccessCode = TPS:TeleportToPrivateServer(10851208543) -- Inside here, you put the ID of the game you want to create a server for.
local PlayerTable = {} -- Make a table for players
for _, player in pairs(game.Players:GetPlayers()) do
table.insert(PlayerTable, player) -- For each player, we'll insert them into the table.
end
TPS:TeleportToReserveServer(10851208543, AccessCode, PlayerTable) -- We teleport all the players at the same time by teleporting the table that they are in.
end
ReserveButtonOne.MouseButton1Click:Connect(TeleportToReserve1)
local ReserveButtonOne = game.StarterGui.ScreenGui.PlayFrame.GameTypeButton1
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local function TeleportToReserve1(player)
local PlayerTable = Players:GetPlayers() -- Make a table for players
local AccessCode = TeleportService:ReserveServer(10851208543)
TeleportService:TeleportToPrivateServer(10851208543, AccessCode, {PlayerTable})
end
ReserveButtonOne.MouseButton1Click:Connect(TeleportToReserve1)
I used your code yet it did not work, Promptly I think the problem is that it is not detecting the player clicking the button, which is really strange as it’s defined correctly.
I added a print after the local AccessCode part and nothing printed.
And the button is not being ‘clicked’ because you are connecting to a button in StarterGui. These buttons do not belong to a player. Instead, index the player’s PlayerGui.
Put this server script in the ScreenGui where your button is:
local reserve = script.Parent.PlayFrame.GameTypeButton1
local debounce = false
reserve.MouseButton1Click:Connect(function()
if debounce then return end -- prevent from being clicked twice too fast
debounce = true
local ts = game:GetService("TeleportService")
local access = ts:ReserveServer(game.PlaceId)
ts:TeleportToPrivateServer(game.PlaceId, access, game.Players:GetPlayers())
warn("Teleporting everybody...")
task.wait(5) -- 5 seconds later you can click the button again
debounce = false
end)