So have a Inventory folder in player’s data folder.
Let’s say for example that I have 6 cobalt bars in my inventory.
DataFolder gets saved in the datastore script in form of a table (That includes saving everything in Inventory folder, in this example cobalt bar with a value of 6 (6 cobalt bars)).
That’s where my problem comes in:
When it gets saved, and loaded later, value of cobalt bar is 0.
I tried printing the cobalt bar value right before it gets saved (in game.Players.PlayerRemoving function),
turns out that the value gets set to 0 when PlayerRemoving function gets called
It prints out 0 instead of 6.
But if I put that line of code inside of PlayerRemoving function in a Local script,
it prints out 6.
As you can see in local script it prints it out before the player disconnects, but in server script it gets print out after the player disconnects
That means in my datastore script when PlayerRemoving function gets called the cobalt bar value becomes 0 before it gets saved, so it saves the 0.
In LocalScript the code executes fast enough but datastore is done in a server script.
I’ve been trying to fix this for quite some time.
Any ideas on how I could fix this problem?
Tell me if I need to provide more info.
Thanks for taking your time to read this!