DataStore error

Okay, in the screenshot you can see my script which should theoretically save the IntValue when the player leaves the game. I need this IntValue to be one for the whole game, that is, if a player changes it, the other players will see it. The problem is that when I click on the button, it changes the IntValue, but in the script, if I put it


to print, it will say that the IntValue is 10, although I’ve done clicks and it should be 5. Also, for some reason, the second print just doesn’t execute. You can see it all in the screenshot. If anything I told manually beforehand that IntValue = 10. And the idea is that the players will click on the button and it will change for all players and also save. HELP PLEASE!

do you change the IntValue on server or client?

If on client, it only updates for the client and stays 10 for the server.

and the second print, i think when you leave the game the game closes faster than the data can save (this will still save your data) but since the game closed before it saved them, the script didn’t execute as the game was already closed.

And how do I know where I update, I use a global script that lies in the workspace, I can assume that it is a client. Yes?

And how do I make sure that first there was a save, and then exit. Although you can probably make a loop every 10 seconds to make a save, you can do so?

oh so you have a server script inside the workspace that changes the value on the server?

oh,
on normal roblox servers the server runs for some more time after all players left

its only on studio where it closes immediately, so no need to worry about it not saving on normal roblox servers.

Okay, so as I understand it, everything works as it should, right?

yes, but anything that is supposed to run after you close the studio won’t run anymore, its closed, scripts not executing anymore.

on roblox servers it works as normal, your scripts have a lot of time to finish