Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with adding an item to a table using DataStore2?? [SOLVED]

Asked by 4 years ago
Edited 4 years ago

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??

0
Hi, I'm having the same problem with datastore2, can you help me?(https://scriptinghelpers.org/questions/113983/how-to-save-a-table-using-datastore2). I'm trying to make a weapon datastore2 but it's been a week struggling and I've also posted 2 other post with no reply. Help please. naturedat 124 — 3y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question