Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

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.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.