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

How can I DataStore Tables?

Asked by 5 years ago

I wanna DataStore this table because I'm trying to make an inventory script. Thing is, is that it won't save. Any help?

01local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerDataV1");
02local itemlist = {}
03 
04game.Players.PlayerAdded:Connect(function(Player)
05    local inv = Instance.new("Folder",Player)
06    inv.Name = "Inventory"
07     local ls = Instance.new("IntValue",inv)
08        ls.Name = "LinkedSword"
09        ls.Value = 6
10local Pistol = Instance.new("IntValue",inv)
11Pistol.Name = "Pistol"
12Pistol.Value = 7
13        table.insert(itemlist, ls.Value)
14table.insert(itemlist, Pistol.Value)
15          Datastore:GetAsync(Player.UserId)
View all 22 lines...

1 answer

Log in to vote
0
Answered by 5 years ago

Hey Bl_ueHistory

Hope this helps I commented on the code a little so you can see it :)

Please remember to upvote if it works! :D

01local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerDataV1");
02local itemlist = {}
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local inv = Instance.new("Folder",player)
06    inv.Name = "Inventory"
07    if Datastore:GetAsync(player.UserId) then -- If the player has data then load it.
08        for i,v in pairs(Datastore:GetAsync(player.UserId)) do -- Loop through the tables in the data
09            print("Name: " .. v[1] .. " || Price: " .. v[2])
10        end
11    else
12        local int = Instance.new("IntValue", inv)
13        int.Name = "LinkedSword"
14        int.Value = 6
15 
View all 29 lines...
Ad

Answer this question