Another Possible way for Saving Teleport/Server Data?

I hope this is the right category

Hello devs,

Recently I discovered another way of saving teleport data, as I’m having a lot of trouble with TeleportOptions. And I wonder whether is it good to use this to save data

First of all, if you haven’t know already, TeleportService:ReserveServer returns the access code to the ReservedServer AND the PrivateServerId for the reserved server. We can write this to get both :

local TPS = game:GetService(“TeleportService”)
local PlaceId = 12345 

local code, serverId = TPS:ReserveServer(PlaceId)

We can get the ServerId by adding another variable to retrieve it.

Now, we can use a GlobalDataStore to save the data, and that is what I’m trying to do! (To be simple, I did not add the code to handle possible fails, but you are supposed to do it)

local DSS = game.DataStoreService
local ServerIdStore = DSS:GetGlobalDataStore(“ServerIdStore”)

local data = {}

ServerIdStore:SetAsync(tostring(ServerId), data) 

And to retrieve data, we can get data using the Server’s PrivateServerId, which returns a string if the server is a Reserved Server, and we should remove the data after we retrieved it :

local DSS = game.DataStoreService
local ServerIdStore = DSS:GetGlobalDataStore(“ServerIdStore”)

local TeleportData = ServerIdStore:GetAsync(game.PrivateServerId)

ServerIdStore:RemoveAsync(game.PrivateServerId)

And that’s the way

What do you think about this way to save data?

Yeah, that’s probably an OK way to do it. However, you should be using GetDataStore instead of GetGlobalDataStore.

You could also use MemoryStoreService, which I’d probably recommend instead. The operations are typically a little faster, and it’s meant for situations where the data is more temporary.

2 Likes

As I’m needing simpler way to do that, I think I would use datastores instead. But thanks for telling me is better to use DataStore but not GlobalDataStore