How would one make a "save-progress" function?

Hello everyone! So my inquiry is that I’ve been recently working on a game that requires certain parts to be saved, for example if a player unlocks a door, leaves the game, joins the game back, and the door should still be unlocked. I’m currently thinking of player zones, where basically the player touches a part which triggers an event to save what just happened, in this case the door being opened and not closed. I’m not exactly sure where to start with this kind of “datastore” if you will, but need some help with this as it is a crucial factor to my game.

2 Likes

I would save the event as it is happening!

Documentation - Roblox Creator Hub has some general info about saving player data, but it’s a little rigid in how it sets up the stats. Still, it’s a good idea to wrap all of this in a module that:

  1. Keeps a data table around for current players in the game for quick access
  2. Loads data when new players join
  3. Provides methods for other scripts to add and update fields in both the local and remote copies
  4. Saves data when a player leaves (and maybe periodically)

Every event that you save should have some unique ID that you track in each player’s data table.

The table can look like whatever you want. I wouldn’t worry too much about it initially.

For example, for key Player_1234 you have this table in your datastore:

{
    VERSION = "1.0", -- this is a good field to put in your datastore from the start 
                     -- so that if you later change your data's format you can build 
                     -- rules for updating old player data to the new formats.
    health = 60,
    currentLocation = "desert",
    subLocation = "oasis1",
    events = {
        forestTempleUnlocked = true,
        hyruleFieldEntered = true,
        hyruleBossDefeated = true,
        desertFlownTo = true,
        desertBossDefeated = false,
        mountainPassUnblocked = false,
        mountainVolcanoShutdown = false
    }
}

Then, when the player dealt the killing blow to the desert boss (for example) you use your data module to update the local and server copies of the data ASAP. Also save again every few minutes, as well as when the player leaves.

I’m not an expert on datastores, but this seems like a good start.

1 Like