Datastore2 MainModule being destroyed

The problem is that sometimes, in the studio and in game, when I leave (the server shuts down as I am the only one there) and sometimes the Datastore2 MainModule which is in server script service gets destroyed. This means that the data is not saved as the script/s got destroyed. In this thread( How to use DataStore2 - Data Store caching and data loss prevention ), the creator of Datastore2 says to put the main module in a place where it will not get destroyed. I put it in server script service as AlvinBlox did in his tutorial but the module gets destroyed. My question is, where should I move the module where it will not get destroyed?

Module scripts only run once. After that, they are done and are not able to save data. Do you have a regular script which is handling the saving of data?

1 Like

Yes I do, 30 charrrrrrrrrrrrrrr

When it errors, it says “script that implemented this callback has been destroyed” And then makes me leave studio, and when this happens in-game, it just does not save the data.

Are you using BindToClose?

1 Like

no, I tried that but how can I do that with Datastore2, I know how to do it with normal datastores. And where should I move the script? Plus, how do I do the bind to close for the datastore2?

I’ve never used datastore2, but I assume there should be something related to BindToClose.

I don’t know why the script is getting destroyed. I guess you could try moving the modulescript to ServerStorage.

1 Like

I tried putting it in server storage. I think it works now but the game and player takes so long to load in and they are not laggy but the respawn time is too high and the player has to reset character twice or more so their avatar loads in.

I’m also taking a super long time to load into Studio. You have this issue too?

1 Like

Yes, is this a issue with my module is it something global. I am in the UK so it may only be in like Europe or something.

No, I’m having issues here in the US too.

1 Like

oh yeah look https://downdetector.co.uk/status/roblox/ i think roblox is down.

Anyway, maybe that is causing issues.

Just be sure to do require at the top of your script only one time. I required a module script, destroyed it, and ran some functions in my script, and it still worked.

1 Like

Only once in a script or in the whole like server script service. because i got like 5 requires for the same module.

Ah, there we go.

You should only require a module script one time. After that, all the needed functions are in your actual script, and you can use them as needed.

Did AlvinBlox have you do that?

No i require them once per script but in the whole game i require the module like 5 times across 5 scripts. And the same error just happened again when i put it in server storage. Alvin Blox did not

Oh, ok. I guess you could upload the module script as an asset and then require the id (if you can still do that) if you had to, but I don’t know why these issues are happening. I’m able to run my code, even after the module script gets destroyed.

1 Like