So i'm been making this Inventory script and I'm using datastore to save tables. I've noticed that sometimes my datastore hasn't been saving, and I can't figure out how to convert it into datastore two. So to my solution I used the function bindtoclose. It was suggested by Incapaz and saves 100% of the time. Although I've been getting a lot of bugs on my inventory concerning duplication whenever the player rejoins. I feel like if I could get a better understanding on this then maybe I can fix the bug. Any help will be apprecated.
Server Script
--This Saves the Inventory
local function OnPlayerRemoving(Player)
for i,v in pairs(Player.InventoryFolder.Inventory:GetChildren()) do
table.insert(itemlist, {v.Name, v.Value})
end
Datastore:SetAsync(Player.UserId, itemlist)
print("Saved Inventory")
end
--Then I put it through the BindToClose function with a bunch of other things
local function OnGameShutdown()
if not RunService:IsStudio() then
local players = Players:GetPlayers()
for _, player in pairs(players) do
OnPlayerRemoving(player)--This is where a run the save script inside the bindtoclose function
end
while true do
wait()
end
else
wait(5)
end
end
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
game:BindToClose(OnGameShutdown)
Regards, Bl_ueHistory
