You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
First note that my game has multiple places. I am trying to make sure that when a person uses a private server to teleport to another place, they’d be teleported to a reserved server, unique to the specific private server and not a public one.
What is the issue?
You simply don’t get teleported to a reserved server…
What solutions have you tried so far?
I’ve tried firstly storing the code of the reserved server as a variable, then recalling it in the parameters of the lua TeleportToPrivateServer() function.
local circuitIDs = {} -- Won't add in the list as it is irrelevant and long.
local circuitNum = script.Parent.Parent.CircuitNumber
local button = script.Parent
local teleportService = game:GetService("TeleportService")
local firstTime = true
local teleportNewServer = Instance.new("TeleportOptions")
teleportNewServer.ShouldReserveServer = true
button.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Teleportation.Visible = true
if game.PrivateServerId == "" then
teleportService:Teleport(circuitIDs[circuitNum.Value][2])
else
if firstTime then
code = teleportService:ReserveServer(circuitIDs[circuitNum.Value][2])
teleportService:TeleportToPrivateServer(circuitIDs[circuitNum.Value][2], code, game.Players.LocalPlayer)
firstTime = false
else
teleportService:TeleportToPrivateServer(circuitIDs[circuitNum.Value][2], code, game.Players.LocalPlayer)
end
end
end)
If I remember correctly, DataModel.PrivateServerId is not replicated to the client. You have to handle teleporting on the server. (Or atleast check wether or not the server is a private server from the server and sending that data to the client)
The PrivateServerId property is not replicated to the client so if you want to teleport on the client you will need a RemoteFunction to check if the server is a private server and then send the value back to the client but the easier way would just be to use a RemoteEvent and teleport on the server.
One last thing though, if I use a server script inside of StarterGui to check if it’s a private server and change a value that the local script can access, would that work?
Something like this:
wait(1)
if game.PrivateServerId ~= "" then
script.Parent.Value = "Private Server"
else
script.Parent.Value = "Public Server"
end
And have this from the local script:
local circuitNum = script.Parent.Parent.CircuitNumber
local button = script.Parent
local teleportService = game:GetService("TeleportService")
local teleportNewServer = Instance.new("TeleportOptions")
teleportNewServer.ShouldReserveServer = true
button.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Teleportation.Visible = true
if script.Parent.ServerType.Value == "Public Server" then
teleportService:Teleport(circuitIDs[circuitNum.Value][2])
else
if circuitIDs[circuitNum.Value][3] == true then
code, privateServerID = teleportService:ReserveServer(circuitIDs[circuitNum.Value][2])
teleportNewServer.ReservedServerAccessCode = code
teleportService:TeleportToPrivateServer(circuitIDs[circuitNum.Value][2], code, {game.Players.LocalPlayer})
circuitIDs[circuitNum.Value][3] = false
else
teleportService:TeleportToPrivateServer(circuitIDs[circuitNum.Value][2], code, {game.Players.LocalPlayer})
end
end
end)
local teleportEvent = -- a RemoteEvent
teleportEvent.OnServerEvent:Connect(function(player) -- the first argument to an OnServerEvent callback is always the player who fired the event
-- reserve the server and teleport the player
end)
Client:
button.MouseButton1Click:Connect(function()
-- fire the teleport RemoteEvent
end)