I have been trying to write a datastore script I was able to create a table but as far as saving it I am not sure how to. I have tried using functions but i want to be able to save the table and update it when the player leaves. Here is the Code:
local DSService = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerAdded:Connect(function(plr)
local key = "player-"..plr.UserId
local savedStats = DSService:GetAsync(key)
if savedStats then
-- not sure what to put here
else
local Data = {
Currency = {Coins = 50, Points = 30},
Inventory = {},
Values = {Gamepass = false}
}
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local key = "player-"..plr.UserId
DSService:SetASync(key,) -- not sure how to save the table when a player leaves
end)
I would like to be able to save the table when the player leaves without having intvalues. Is this possible if so any help would be greatly appreciated.

2 comments
You can save a table the same way as you save any other value
I have tried that is the reason i came here hoping for a example or better understanding