Hello,
In my game to change gamemodes, I save the players data before teleporting the player to the new server. Currently, this can take up to 30 seconds to save the players data then teleport which is annoying. Ive had a few people come to be about this aswell. I save the data beforehand to prevent any data issues with switching servers and getting data before its set.
Is there any way this can be sped up? Ive been told 5 seconds is how long you should wait before re attempting to set data, so im not sure how to speed this up.
function module.setPlayerData(player)
local playerData = module.setDataToTemplate(player) -- returns user data in a table which can be stored
local userId
local playerName
if typeof(player) == "number" then
userId = player
-- i probably should change this but its not a huge issue really
for i, folder in pairs(ServerStorage.PlayerData:GetChildren()) do
if folder.userId.Value == userId then
playerName = folder.Name
continue
end
end
else
playerName = player.Name
userId = player.UserId
end
if playerData and ServerStorage:WaitForChild("PlayerData")[playerName].level.Value ~= 0 then -- check to make sure there's actually data to save
for i = 1,NUMBER_OF_ATTEMPTS do
local success = pcall(function()
PlayerDataStore:SetAsync(userId,playerData)
end)
if success == true then
continue
end
wait(5.5)
end
for i = 1,NUMBER_OF_ATTEMPTS do
local success = pcall(function()
PlayerBackupDataStore:SetAsync(userId,playerData)
end)
if success == true then
return true
end
wait(5.5)
end
elseif playerData and playerData.level.Value == 0 then
return true
end
return nil
end
Also, if anyone knows how i can implement UpdateAsync, please tell me how i can do so. Im very confused on how UpdateAsync works.
Thanks to anyone who can help with this!