So, I have a game that uses DataStore2. I use DataStore2 to save a table in which the player's skins are held. My code is as follows:
local skinsData = DataStore2("skins", player) local skins = skinsData:Get("Tornado") -- Don't worry about this code. local debrisData = DataStore2("debris", player) local debrisDataValue = debrisData:Get() local price = ServerStorage.Skins[item].Price if debrisDataValue >= price.Value and not owned then debrisData:Increment(-price.Value) -- NEED HELP HERE!!!!!!!! return true end
Ok, so where I put "NEED HELP HERE," I have tried the following solutions: table.insert(skinsData, item) - Doesn't work skinsData:Increment(item) - Errors skinsData:Set(skinsData, item) - Errors
How would I simply add this to the existing table??
Lol, as I was writing this I figured it out! I simply had to do:
local skinsData = DataStore2("skins", player) local skins = skinsData:Get("Tornado") local skinsTable = {} for i, skin in pairs(skinsData:Get()) do table.insert(skinsTable, skin) end if debrisDataValue >= price.Value and not owned then debrisData:Increment(-price.Value) table.insert(skinsTable, item) skinsData:Set(skinsTable) return true end
Basically, looping through all of the skins, adding them to a table, inserting the item into said table, then using :Set to set the skinsData to that table.