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

My DataStore isn't working and has no error, can anyone help me fix this?

Asked by
imaski4 42
7 years ago

Can you guys tell me what the problem is?

01ds = game:GetService("DataStoreService"):GetDataStore("RM")
02 
03game.Players.PlayerAdded:connect(function(player)
04    local key = "id-" .. player.userId
05    local gs = ds:GetAsync(key)
06    tbl = {}
07    local gui = player.PlayerGui:WaitForChild("Inventory")
08    local frame = gui:WaitForChild("Inventry")
09    local list1 = frame:WaitForChild("list"):WaitForChild("1")
10    table.insert(tbl, list1.Image.Texture.Value)
11    table.insert(tbl, list1.Item.Text)
12    table.insert(tbl, list1.Qty.qty.Value)
13    -- I have 3 table.inserts only because it gave me an error when I put all these in one ok
14    if gs then
15        tbl[1] = gs[1]
View all 26 lines...

2 answers

Log in to vote
0
Answered by 7 years ago

The problem is you are setting the table to the datastore if the datastore exists then setting the datastore to the table when the player leaves (setting it to itself). This is what you should do.

01ds = game:GetService("DataStoreService"):GetDataStore("RM")
02 
03game.Players.PlayerAdded:connect(function(player)
04    local key = "id-" .. player.userId
05    local gs = ds:GetAsync(key)
06    local gui = player.PlayerGui:WaitForChild("Inventory")
07    local frame = gui:WaitForChild("Inventry")
08    local list1 = frame:WaitForChild("list"):WaitForChild("1")
09    if gs then
10        list1.Image.Texture.Value = gs[1]
11        list1.Item.Text = gs[2]
12        list1.Qty.qty.Value = gs[3]
13    else
14        local tbl = {}
15        table.insert(tbl, list1.Image.Texture.Value)
View all 32 lines...

Now when the player joins the datastore values will be loaded into list1 and when they leave list1's value will be saved to the datastore

0
thanks imaski4 42 — 7y
0
No problem. Datastores are hard to get the hang of, but once you do they can be very useful. I use them to save stats, ranks, and ban times. justoboy13 153 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Not sure if this is your problem but in line 8: local frame = gui:WaitForChild("Inventry")

Answer this question