Ok, I’ve returned and I’ve made some progress on saving/loading tables.
I have figured out saving/loading, kind of. I think there is an issue with Saving, because printing values gives me the same bug.
Heres the script, but the issue is that whenever rejoining, no matter what items were in your inventory, multiples of the 2 same items will appear. Here is the script, I have a feeling its just me being stupid and missing the obvious, but I can’t figure it out.
local players = game:GetService("Players")
local DS2 = require(game.ServerScriptService.DataStore2)
game.Players.PlayerAdded:Connect(function(player)
wait(3)
local saveslottimer = Instance.new("NumberValue", player)
saveslottimer.Name = "SaveSelector"
saveslottimer.Value = 0
repeat
wait()
until saveslottimer.Value == 1
local saveslot = player.SaveSlot
local stats = Instance.new("Folder", player)
stats.Name = "Stats"
local money = Instance.new("NumberValue", stats)
money.Name = "Money"
local er = Instance.new("NumberValue", stats)
er.Name = "Eridium"
local level = Instance.new("NumberValue", stats)
level.Name = "Level"
local exp = Instance.new("NumberValue", stats)
exp.Name = "Experience"
local maxexp = Instance.new("NumberValue", stats)
maxexp.Name = "MaxExperience"
local inv = Instance.new("Folder", player)
inv.Name = "Inventory"
DS2.Combine(saveslot.Value, "Money", "Eridium", "Level", "Experience", "MaxExperience", "Inventory")
local moneystore = DS2("Money", player)
local erstore = DS2("Eridium", player)
local levelstore = DS2("Level", player)
local expstore = DS2("Experience", player)
local maxexpstore = DS2("MaxExperience", player)
local invstore = DS2("Inventory", player)
local invholder = {}
money.Value = moneystore:Get(500)
er.Value = erstore:Get(0)
level.Value = levelstore:Get(1)
exp.Value = expstore:Get(0)
maxexp.Value = maxexpstore:Get(500)
invholder = invstore:Get()
wait(1)
saveslottimer.Value = 2
money.Changed:Connect(function()
moneystore:Set(money.Value)
end)
er.Changed:Connect(function()
erstore:Set(er.Value)
end)
level.Changed:Connect(function()
levelstore:Set(level.Value)
end)
exp.Changed:Connect(function()
expstore:Set(exp.Value)
end)
maxexp.Changed:Connect(function()
maxexpstore:Set(maxexp.Value)
end)
local function SaveInv()
invholder = {}
for i,v in pairs(inv:GetChildren()) do
local realitem = game.ReplicatedStorage.Items[v.Name]
local required = require(realitem.Info.Information)
invholder[tostring(required.Id)] = v.Value
end
return invholder
end
inv.ChildAdded:Connect(function()
SaveInv()
wait(.5)
invstore:Set(invholder)
end)
inv.ChildRemoved:Connect(function()
SaveInv()
wait(.5)
invstore:Set(invholder)
end)
wait(1)
if invholder == nil then
local item1 = Instance.new("NumberValue")
item1.Name = "Stone Mine"
item1.Value = 3
item1.Parent = inv
local item2 = Instance.new("NumberValue")
item2.Name = "Basic Furnace"
item2.Value = 1
item2.Parent = inv
local item3 = Instance.new("NumberValue")
item3.Name = "Basic Conveyor"
item3.Value = 10
item3.Parent = inv
else
for i,v in pairs(invholder) do
for i,a in pairs(game.ReplicatedStorage.Items:GetChildren()) do
local required = require(game.ReplicatedStorage.Items[a.Name].Info.Information)
if required.Id == tonumber(i) then
local item = Instance.new("NumberValue")
item.Name = a.Name
item.Value = v
item.Parent = inv
end
end
end
end
end)
The bits about ‘required’ is just a module script with info about each item in it. Each item has its own ID, which it saves, as well as the value.