DataStore2 | Value not saving

So basically when the player already has something in their inventory I add the value + itself then + 1 but the problem is it doesnt want to save at all

Heres a code snippet :

for i,v in ipairs(Pickupables.Weapons) do
		if item and item.Name == v and (item.PrimaryPart.Position - humrp.Position).Magnitude <= 5 and item then
			if Inventory:FindFirstChild(item.Name) then
				for i,v in pairs(Inventory:GetChildren()) do
					if v.Name == item.Name then
						print(v.Name)
						v.Value = v.Value + 1
					end
				end
			elseif not Inventory:FindFirstChild(item.Name) then
				local Put = Instance.new("NumberValue")
				Put.Name = item.Name
				Put.Value = 1
				print("The player has just picked up a "..item.Name)
				table.insert(InventoryTable, {Put.Name, Put.Value})
				InventoryStore:Set(InventoryTable)
				item:Destroy()
				print("Testing")
			end
		end
	end
end)

The snippet shown doesn’t include many of the variable definitions and also doesn’t show where you’ve tried to load the value.

What’s making you believe that it isn’t saving?

Im not really sure I think it’s maybe because I didnt implement it in the OnUpdate function, here i the snippet of the OnUpdate function

local function UpdateInventory(Default)
		local tab = InventoryStore:GetTable(Defaults)
		for i,v in pairs(tab) do
			if Inventory:FindFirstChild(v) then
		else
			print("Adding New Item!")
			local item = Instance.new("NumberValue")
			item.Name = v[1]
			item.Value = v[2]
			item.Parent = Inventory
		end
	end
end

It always passes through the first check, and I dont know why because the name of the item in the table is in the inventory

Well you seem to be passing an empty variable to GetTable, as you’ve given it Defaults, yet your function only defines Default as the argument (no s).

GetTable is also for use with dictionaries, but from your Set function usable it looks like you’re storing an array instead. Try switching to Get instead of GetTable.

Alright let me try that, thanks!

It is still not saving the value when I update it, good try though

Any errors?

And I think it’s very incorrect to just claim it doesn’t save. Your evidence for it “not saving” is that it won’t load, which means there’s two places where an issue might be occurring - either at the point of saving, or the point of loading.

To assume it is only the saving that is an issue without good reason cuts your chances of finding and fixing the problem in half.

1 Like

I definitely think it’s the saving that is the problem as of now

Also I said it wasnt saving not loading, you cant load something you didnt save :rofl:

Are you sure the value increments at all before attempting to save?
And

if that’s what you save, then

here v is not one string value, but an array.

edit:

if you’re searching for Put.Name then do something like

 for i = 1, #tab do
     x:FindFirstChild(tab[i][1])
 end