Store your place version
Personally, I'd store the place version
of your game with data store. Once you've stored your place version, you can then compare it to it's current place version
to see if it's new. If it is, then create some function that sets all your keys in OrderedDataStore
to nil.
Implementation
Implementing this is pretty simple. You can get your game's current version with game.PlaceVersion, and just save it directly to a data store. First, just create your desired data store to save the version number:
2 | local datastore = game:GetService( "DataStoreService" ) |
5 | local placeData = datastore:GetDataStore( "PlaceData" ) |
8 | local placeVersion = game.PlaceVersion |
Next, send a get request to the data store to retrieve what will represent the last place version saved.
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local placeData = datastore:GetDataStore( "PlaceData" ) |
03 | local placeVersion = game.PlaceVersion |
06 | local lastPlaceVersion = placeData:GetAsync( "LastPlaceVersion" ) |
09 | if lastPlaceVersion = = nil then |
10 | placeData:SetAsync( "LastPlaceVersion" , placeVersion) |
11 | lastPlaceVersion = placeVersion |
Now last but not least, compare "lastPlaceVersion" with "placeVersion" and see if they're not equal to each other. If they're not, that means you updated your place since a user last played, and you can then set all your OrderedDataStore keys to nil. Here would be the final implementation:
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local placeData = datastore:GetDataStore( "PlaceData" ) |
03 | local placeVersion = game.PlaceVersion |
05 | local lastPlaceVersion do |
06 | lastPlaceVersion = placeData:GetAsync( "LastPlaceVersion" ) |
07 | if lastPlaceVersion = = nil then |
08 | placeData:SetAsync( "LastPlaceVersion" , placeVersion) |
09 | lastPlaceVersion = placeVersion |
14 | if placeVersion ~ = lastPlaceVersion then |
17 | print ( "Game was updated from version: " .. lastPlaceVersion .. " to version: " .. placeVersion) |
21 | print ( "Your ordered data store code here" ) |
25 | placeData:UpdateAsync( "LastPlaceVersion" , function () |
That's how I'd personally go about doing this, but if you're confused about anything or if you have any questions, just let me know. I've also tested this in studio before posting the answer to ensure it works.