DataStore2 refuses to save changed boolean value

I currently have a function that should update values inside of a table I’m using to house all inventory data. However, the function doesn’t work at all.

for _,item in pairs(inventory:GetTable(inv)) do
	if item.ID == value then
		print(item.ID) -- Debugging
		print(item.Name) -- Debugging
		print("same id!") -- Debugging
		item.Equipped = true -- Setting value inside specific item in inventory to true
		inventory:Set(inv) -- Supposedly saving changes
		print(item.Equipped) -- Returns true...
		print(inventory:GetTable(inv)) -- ...Yet not in here?
		end
end

Upon printing the table, the .Equipped line is returned as false, as explained in the code. This genuinely makes no sense to me and it’s tiring me out having to find a way to solve this without any proper documentation on DS2’s part.

I’ve also tried using :Save(), using :Set() afterwards, with no results. DS2 is updated to the latest Github version, so that’s not an issue.

I don’t normally use the GetTable method but I think I can help a bit.

A small explanation:
So, in your loop, your looping through the returned table but your setting the value (using Set) to inv which isn’t what you looped through (correct me if I’m wrong) so you aren’t changing any values in the table inv.

Fixing:
You can save the table returned from the GetTable method as a variable, then, in the loop, loop through that variable, change the “properties” their and use the Set function on that same table, you can also use Set after the loop is over but your choice here.

ACTUAL lifesaver right here. I had that lingering thought that I wasn’t actually saving properly, so thank you so much!

Thanks! ..

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.