Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use datastores for inventory saving?

Asked by 4 years ago

In my game, I want there to be inventory saving. Say if the player bought clothes, it would save what clothes they have on, and load them back in when they rejoined. I don't know much about datastores, and my current attempts have failed. Does anyone know a bit more about datastores that could help me with this?

3 answers

Log in to vote
1
Answered by 4 years ago

https://developer.roblox.com/en-us/articles/Data-store

Ad
Log in to vote
0
Answered by 4 years ago

I personally would recommend that you store a string of all names in a table and save that, then when they hop on the game again, you iterate through that table and where you keep clothes. If there is a match, clone it to them and whatever you have to do to make them wear it. Hope that gets you in the right direction!

Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
4 years ago

Use this code to get their inventory:

game.Players.PlayerRemoving:Connect(function(player)
    local char = player.Character

    for i,v in pairs (player.Backpack:GetChildren()) do
        table.insert(table,#table + 1,v)
    end

    for i,v in pairs (char:GetChildren()) do
        if v:IsA("Tool") then
            table.insert(table,#table + 1,v)
            break
        end
    end

    --Data store code
end)

Then DataStore it all. Hope this helped!

Answer this question