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.
01 | ds = game:GetService( "DataStoreService" ):GetDataStore( "RM" ) |
03 | game.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 list 1 = frame:WaitForChild( "list" ):WaitForChild( "1" ) |
10 | list 1. Image.Texture.Value = gs [ 1 ] |
11 | list 1. Item.Text = gs [ 2 ] |
12 | list 1. Qty.qty.Value = gs [ 3 ] |
15 | table.insert(tbl, list 1. Image.Texture.Value) |
16 | table.insert(tbl, list 1. Item.Text) |
17 | table.insert(tbl, list 1. Qty.qty.Value) |
22 | game.Players.PlayerRemoving:connect( function (player) |
23 | local key = "id-" .. player.userId |
24 | local gui = player.PlayerGui:WaitForChild( "Inventory" ) |
25 | local frame = gui:WaitForChild( "Inventry" ) |
26 | local list 1 = frame:WaitForChild( "list" ):WaitForChild( "1" ) |
28 | table.insert(tbl, list 1. Image.Texture.Value) |
29 | table.insert(tbl, list 1. Item.Text) |
30 | table.insert(tbl, list 1. Qty.qty.Value) |
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