So I have an inventory GUI and I want to make it save what's in your inventory on death.
I've seen the ROBLOX Wiki for datastores but I'm not sure how I would apply that to a players' GUI.
I've already set up a data store for a player stats and what works fine but here's me trying to save inventory values:
game.Players.PlayerAdded:connect(function(Player)
local playerKey = "player: "..Player.userId
local savedValues = DataStore:GetAsync(playerKey)
if savedValues then
for i, v in pairs(inventorySlots) do
wait()
v.Ammt.Value = savedValues[1]
v.EquipVal.Value = savedValues[2]
v.Rarity.Value = savedValues[3]
v.slotValue.Value = savedValues[4]
end
else
local valuesToSave = {v.Ammt.Value, v.EquipVal.Value, v.Rarity.Value, v.slotValue.Value}
DataStore:SetAsync(playerKey, valuesToSave)
end
end)

2 comments
"on death"? You only save (SetAsync) when the player leaves. So, make a PlayerRemoving function.
Yeah because in the long run it has to save what the player has when they leave. I just thought an "on death" explanation would be easier for someone to explain and then I would convert it myself.