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)

4 comments
Is there any ways to counter this? This is gonna be a problem to me :/
Do you want the database to save the highest amount of ore they have first ? if so just get their ore amount then set that as PlayerData[ORE AMOUNT] = {["Type"] = "ORE NAME", ["Amount"] = AMOUNT HERE}
Nevermind, i figured it out :D
I am new to Roblox LUA the first time I started using DataStore I had the same thing happen to me. If u need any more help just ask.