Teleport Logic Issue

Hey everyone! My question is at the bottom of the post. Thank you for your time.

I want to Teleport a player to a reserved server, save the AccessCode and the PrivateServerId into a DataStore before the player gets teleported.
I got it using these steps, but someone suggest me to not use ReserveServer() cause its outdated:

  • Player clicks something
  • Server checks if player has an existing server in DataStore
  • If not, creates one by using ReserveServer(), saves data into DataStore
  • If DataStore fails, tries again a few times
  • If DataStore succeded teleport the player with TeleportAsync() and TeleportOptions.ReservedServerAccessCode from the ReserveServer() result
  • Player arrives to the new reserved server place, on join server checks player’s DataStore, if player belongs to that reserved server let player stay, if not kick.

BUT… Im using TeleportAsync() with TeleportOptions to include the AccessCode, and I want to avoid using ReserveServer() and use TeleportOptions.ShouldReserveServer = true instead.

Which means, the Teleporting occurs “before” the DataStore saves the data, possibly causing the player arrives into the new reserved server without DataStore saved, causing the player to be kicked out…

  • Player clicks something
  • Server checks if player has an existing server in DataStore
  • If not, TeleportAsync() with TeleportOptions.ShouldReserveServer = true occurs
  • If Teleport went correctly, I get the AccessCode and the PrivateServerId from TeleportAsyncResult and save it into DataStore.
  • If DataStore failed saving, it tries again a few times (Player already got teleported into reserved server)
  • Player is in the new reserved server, on join server checks their DataStore, no data found, kicks the player…

So… my question is, how to get the AccessCode and PrivateServerId from a successful TeleportAsync().Result but, delay the player teleporting until DataStore finished saving data correctly? Or should I use ReserveServer() no matter if its outdated?

This is for a customer, and they are worried about if hackers/exploiters are capable of faking the UserId on join and server checking that (which I said no, its not possible… but Im not sure) and they desire to not use outdated ReserveServer(), and I cant find a way to get the AccessCode and PrivateServerId with TeleportAsync() without teleporting player before saving the DataStore…

ReserveServer isn’t deprecated by any means so why not?
Plus, I like to use MemoryStoreService for my servers, you should take a look into it and see if its worth your use case.

I’d recommend using TeleportInitFailed and save their data just before leaving, so if the teleport fails, you still ‘remember’ what server you’re trying to take them to.

1 Like

I prefer to use ReserveServer() but posts in DevForum says its outdated and TeleportToPrivateServer() and ReserverServer() will be depracated at some point.

I will check MemoryStoreServices thank you!

Im using TeleportInitFailed only to retry the teleport, but, I wont get the successful TeleportAsyncResult with AccessCode and PrivateServerId until the teleport is successful, so theres no way to make sure that data is saved correctly into DataStore before the teleport happens

Nope, hold on… let me check…
When TeleportInitFailed triggers, it has a result with the AccessCode and PrivateServerId, even if the teleport failed? I thought the result contains that data only if it was successful…

Anyway, if the teleport went fine, the player is arriving the reserved server before the DataStore finished saving (if DataStore is failing and taking more tries to save)

Why not save it to the datastore, then teleport the player?

You could use BindToClose and have the server itself remove all data about itself beforehand. Using MemoryStoreService, you can use PrivateServerId as the key for the AccessCode
local accessCode = queue:GetAsync(game.PrivateServerId)

1 Like

Thats what I did, but it requires me to use ReserveServer() which supposedly is outdated and will be depracated

It is not deprecated and works perfectly.

1 Like

I will still using ReserveServer()… I cant figure out another way to get the AccessCode and PrivateServerId before the DataStore tries and teleporting at the end.
Thank you so much! c:

local accessCode, privateServerId = TPService:ReserveServer(args)

– run datastore saving code (it yields, run in a pcall)
– teleport player