How to change value in this dictionary

p.s: I’m bad when it comes to programming terms, but I’m pretty sure this is a dictionary because it has the key and then the value or whatever.

So I have a module script for player data and I have this table which will hold stuff the player owns the number will be the amount of it however when working on my shop script I couldn’t seem to figure out how to change the number.

Upgrades = { 
	["Stools"] = 4,
	["Tables"] = 6,
}

I thought doing playerData:GetData(player,"Upgrades")[itemToBuy.Name] + 1 would work however I guess it doesn’t update so if I was trying to increase stools it’s always just gonna end up being 5 lol. Anyways not sure how to change the number.

We need more code to see the full example of the issue.

From what I understand, you need to use a set value.

local currentData = playerData:GetData(player, "Upgrades")
currentData[itemToBuy.Name] += 1

playerData:SetData(currentData)

This basically sets the new data to the entire data, you’re editing the table, not the datastore itself.

Wait so should I make another function inside my module script for setting data then?

1 Like

Yes. You need to actually set the datastore, when you get data you’re copying the table, you aren’t editing a direct reference to the datastore. I would use a :SetData() method to completely overwrite something like that. Then, for numerical values, make an :Increment(amount) value.