I would recommend just sending the players’ names through arguments. If this is server side, then when you look at what the playerGui is, it’s probably coming back as nil, because that would be locally stored
I dont seem to understand what your saying, also it doesn’t come out as nil as seen here, I added this line of code print(playergui.Parent.Name)
remember, you need the player for a teleport:
TeleportService:Teleport(placeID, Player)
But I am using TeleportService:TeleportToPrivateServer
not TeleportService:Teleport
I cant remember quite well, but, TeleportToPrivateServer()
uses an array of players and not a player object.
TeleportToPrivateServer(PlaceID, code, {plr1, plr2, plr3} )
And you are trying to teleport only the player object each iteration of the loop with
local playertoteleport = game.Players:FindFirstChild(v.PlayerName.Text)
tpservice:TeleportToPrivateServer(placeid, server, playertoteleport)
Right now Im working with Teleport Service, and Teleporting to reserved servers too, and someone told me that TeleportToPrivateServer()
is kinda useless now, cause all teleport functions has been added into TeleportAsync()
:
And maybe adding a SaveTeleport module with TeleportService.TeleportInitFailed
, like the example in the documentation would help a lot while doing this
You need to use an array for TeleportService.
I also would recommend using TeleportAsync instead of TeleportToPrivateServer. If you’re trying to teleport the user to their own reserved server then something like this should work:
game.ReplicatedStorage.Remotes.TeleportParty.OnServerEvent:Connect(function(plr)
local playergui = plr.PlayerGui
local TeleportService = game:GetService("TeleportService")
local PlaceID = game.PlaceId
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true
for i,v in pairs(playergui.Party.PlayersInParty.PlayerList:GetChildren()) do
if v then
if v:IsA('Frame') then
local playertoteleport = game.Players:FindFirstChild(v.PlayerName.Text)
print(playertoteleport.UserId)
TeleportService:TeleportAsync(PlaceID, {playertoteleport}, teleportOptions)
print('teleport for '.. playertoteleport.Name)
end
end
end
end)
Yup, its exactly what I was saying, it needs an array and TeleportAsync()
should be used instead of TeleportToPrivateServer()
, and I don’t know if it’s a matter of taste… but, we’ve been talking about this on my post. I think its more efficient creating the reserved server code before teleporting the player, instead of using ShouldReserveServer = true
into TeleportOptions
By just doing:
local code = TeleportService:ReserveServer(placeID)
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerAccessCode = code
TeleportService:TeleportAsync(PlaceID, {Player}, teleportOptions)
I would do something like this:
local TeleportService = game:GetService("TeleportService")
local PlaceID = game.PlaceId
game.ReplicatedStorage.Remotes.TeleportParty.OnServerEvent:Connect(function(plr)
local playergui = plr.PlayerGui
-- Save this server code in DataStore if you need it later
local serverCode = TeleportService:ReserveServer(PlaceID)
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerAccessCode = serverCode
-- Array of players that will be teleported
local PlayersToTP = {}
for i,v in pairs(playergui.Party.PlayersInParty.PlayerList:GetChildren()) do
if v then
if v:IsA('Frame') then
local playertoteleport = game.Players:FindFirstChild(v.PlayerName.Text)
-- If player is found, add it into an array
if playertoteleport then
table.insert(PlayersToTP, playertoteleport)
print(playertoteleport.UserId, "added into array")
end
end
end
end
-- Teleport entire array of players
warn("Teleporting array of players to reserved server", serverCode)
TeleportService:TeleportAsync(PlaceID, PlayersToTP, teleportOptions)
end)
I tested your script, and it says attempt to teleport to a restricited place, does the game have to be public or does Studio Access to Api Services have to be enabled?
Teleportation doesnt work in Studio, only in game, it can be private
I tried it in game, same result.
I tried the script 30 mins ago, works fine for me.
I simulated your GUI, I just added a frame with a textlabel with my user name, and the script placed me inside the array on loop after pushing the button, and then teleported me to a reserved server with the correct code, works nicely
Any other info or details about your place?
Does it have to be on? I have it off and I cant turn it on. Do I have to be game owner to turn it on?
Depending if you want to teleport to other peoples games or places, not sure.
I think that only works in Studio. Its giving your Studio rights to connect with Roblox APIs.
I guess that doesnt make any difference to real game, only Studio access
Does the game need to be public? I just testing it right now and it still says teleport failed to a restricted place, do both the starting place and the place I’m teleporting to need to be public?
Nope, Im working on my teleport system that uses reserved servers too, and its a private game, not public, and its working normally
You have any idea why its not working, I have no idea.
?