Hello! I’m not too good with datastores, but I was wondering how I would add/remove an item that is being saved.
For example, if a new player joins, I would give them some new data such as:
local tableOfData = {
["Money"] = 10,
["Level"] = 1,
["Rank"] = "Noob"
}
However, if they already have data, I would just load it in. I was wondering if there was a way to add a new value to the table for players who already have data saved. I’ve tried something like this:
local tableOfData = {
["Money"] = 10,
["Level"] = 1,
["Rank"] = "Noob"
}
if not table.find(tableOfData[player.UserId], "Diamonds") then
table.insert(tableOfData[player.UserId], "Diamonds")
tableOfData[player.UserId].Diamonds = 0
end
But this doesn’t work. I’d like it to be the same the other values. The table should look like this:
local tableOfData = {
["Money"] = 10,
["Level"] = 1,
["Rank"] = "Noob"
["Diamonds"] = 0
}
Instead, it looks like this:
local tableOfData = {
[1] = "Diamonds"
["Money"] = 10,
["Level"] = 1,
["Rank"] = "Noob"
}
I’m not sure how to add it so that the new value is in the same format as the others. Sorry if this question is a bit confusing, but if anyone could help, that would be great! Thanks.