local data = {}
data.gem=100
InventoryStore:SetAsync(player.UserId, data)
strangely, this works in roblox studio across multiple sessions and even when i read the value in game.
However when i try to do the above in game, it doesn’t even save.
It doesn’t mean prevents the server from shutting down until data store is saved. It means that when the server is closing(examples: the last player leaves in the server, the server shuts down for some reason), this event will be triggered and does whatever code inside it. It’s very useful if you need to save data while the game is gonna close for updates or whatever.
It won’t yield till the function is completed executing, as you said, but it does wait a maximum of 30 seconds for the function bound to be completed. After that it shuts down the server regardless of it completing or not.
The issue is with not using pcalls, saving/getting data is not done inside Studio, it’s done outside of Roblox. So you wrap your get/save functions or methods into a pcall so that if an error were to occur, it won’t break the entire script.
Do you change your values locally or on the server side? If so, changes made on the client will not replicate to the server as FilteringEnabled prevents that. Therefore, you would have to make use of Remote events.
Therefore your code should be somewhat like this:
local data = {}
data.gem = 100
local success, errormessage = pcall(function()
InventoryStore:SetAsync(player.UserId, data)
end)
--// handling
For anyone, here is the indented code properly formatted;
local data = {}
data.gem = 100
InventoryStore:SetAsync(player.UserId, data)
How’s he supposed to indent 3 lines with no scoping? It’s really not that big a deal, and the poor formatting is still readable too (it’s just 3 lines).
Also, you should directly call the function you’re pcalling instead of wrapping it in an anonymous function.
As in, do not do it like this:
But instead like this:
local success, err = pcall(InventoryStore.SetAsync, InventoryStore, player.UserId, data)