The time I first went on, I had 50 iron, and 2 gold. The next time, now I have 50 iron and 2 tin. The gold somewhat changed to tin, and I can't find the problem whatsoever.
This is what i'm talking about here Look at this: LINK The location of those is at ReplicatedStorage, if it helps.
SCRIPT BELOW
local DSService = game:GetService('DataStoreService'):GetDataStore('stpre') local Items = game.ReplicatedStorage.CONFIG.Materials:GetChildren() game.Players.PlayerAdded:connect(function(plr) local key = 'id'..plr.userId local savedvalues = DSService:GetAsync(key) local main = Instance.new('Model', plr) main.Name = 'inventory' local inv = Instance.new('Model', main) inv.Name = 'materials' local wepinv = Instance.new('Model', main) wepinv.Name = 'weapons' local utils = Instance.new('Model', main) utils.Name = 'utilities' for _,v in pairs(Items) do local ins = Instance.new('IntValue', inv) ins.Name = v.ItemName.Value end if savedvalues then for _,v in pairs(Items) do for _,vv in pairs(inv:GetChildren()) do if vv.Name == v.ItemName.Value then vv.Value = savedvalues[v.ID.Value] end end end else local vts = {} for _, v in pairs(Items) do for _, vv in pairs(inv:GetChildren()) do if vv.Name == v.ItemName.Value then table.insert(vts,vv.Value) end end end DSService:SetAsync(key, vts) end end) game.Players.PlayerRemoving:connect(function(plr) local key = 'id'..plr.userId local items = plr.inventory.materials local vts = {} for _, v in pairs(Items) do for _, vv in pairs(items:GetChildren()) do if vv.Name == v.ItemName.Value then table.insert(vts,vv.Value) end end end DSService:SetAsync(key, vts) end)
I would have uploaded the code for the problem. but here is a reason I can guess with the information you gived. When you get list of items using GetChildren() and its getting the childrens over again but they are not inorder cause when u create new lets say Model with name of A1 and other one A2 then you save them in a table Example
local oldMaterials = {A1 =, A2, A3} same has Old but this time lets say new Model was added Named AB1 local newMaterials = {AB1, A1, A2, A3} When a new object or a Name that is Alpbatical order starting with A if their no letter after A then it order letters then Numbers A0 becomes first unless their was AA or AA0 or AB or AB0 my point is you might want to create a order list that will load them inorder when saving and loading. I could create a simple/complex script for that but I am sure their a better way of doing this I am kinda new to Roblox LUA.