How to save the script the player left off on in a datastore

Hello everyone! I’m trying to make a single player story/adventure game, and I’m making the game progression works with a bunch of different scripts. So I wanted to make a save game that works like this:


Someone give me the ideia to save the scripts the player left off on in a datastore, and then when he joins the game again, the scripts that already had been ran are disabled and the next ones are enabled, but I have no ideia how to do this…

Could you get the name of the script they left off at and then add the name to the data base. Then when the player joins just run that script and disable the others or something like that.

To accomplish this you can write to a data key every time a script completes. When the player joins, read their data key and see what script to enable (with none enabled by default).

But, I would recommend a different hierarchy within a chapter-based storygame. Where each chapter starts through a singular module call, and that module call writes to the player’s data when it completes. This would be much more organized than numerous top-level server scripts.

PrimaryModule:StartChapter(GetAsync(UserId)), or something like that. In general writing within modules like this will lead to more organization. With this system it is also very easy to start the next chapter using module’s self data.

2 Likes

Maybe you could save the scripts content. Script.Source and then when the player rejoins you do Script.Source = playersdata["script1source"] (just an example don’t actually use this code.

Edit: Do not use. Misinformation (my bad)

The LuaSourceContainer.Source property is locked for normal scripts

LocalScripts work though right?

I would assume it’s LocalScripts because I don’t know what benefit saving a server script would do for the OP

It’s locked for any scripts with identity level below 3 (or 5?)

Oh, I didn’t realize that. My bad

That property is locked and is not a good idea anyways it doesn’t really make sense.

What you do is have variable that stores what stage the player is at in the game, save the variable, then load the variable and run the code accordingly

Ok… that’s sounds like exactly what I want. But how?

Like I said via a database. You can use the datastore service to store the data and then use some type of if statment or something to check what is in the data