Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Run next few parts of code at the same time?

Hi guys!

When a player leaves from my game, I want to save their stats.

However, for some reason, only the first few saves actually proper save. I have a feeling this is because when the player has left the Data can't save?

So, is there anyway to run all these saves at the same time so that they can all save properly? :) Thanks!

SAVING:

local function save(player,name)
    local folder = player:FindFirstChild(name)
    local data = {}
    for k,v in pairs(folder:GetChildren()) do
        data[v.Name] = v.Value
    end
    for i=1,3 do
        if pcall(DS.SetAsync,DS,player.userId.."_"..name,data) then
            return print("BACKEND HANDLER: Data saved successfully for",player)
        end
    end
    warn("BACKEND HANDLER: Couldn't save data for",player)
end

Players.PlayerRemoving:connect(function(plr)
    saveplayerdata(plr,"Traps")
    save(plr,"PlayerMapTimes")
    save(plr,"PlayerModel")
    saveplayerdata(plr,"TwitterCodes")
    saveplayerdata(plr,"Equipped")
    saveplayerdata(plr,"Achievements")
end)

1 answer

Although you didn't post the function, I could have an idea. You should instead have a table as the 2nd parameter, with all values you need. That's how I personally save data.

1 comment

0

OK, thanks! I have edited the post to contain my saving :) Any suggestions to edit it specifically?

This discussion is preserved as it was. New answers, comments, and votes are closed.