Inserting Tables into Tables and Saving

So, I am trying to make a game where players go to solve certain “mysteries” in certain places, and each of these “places” has a few different mysteries to solve. Once they have solved the mystery, I want a datastore to record that they have solved the mystery, but also WHICH PLACE that mystery is.

What I want to be stored in each player’s datastore is something like this:

SolvedMysteries = {PlaceOne = {"GasStationMystery","ShopMystery"}, PlaceTwo = {"BankMystery", "HouseMystery"}}

How would I use :SetAsync to…
take the items the player already has in SolvedMysteries using :GetAsync (I know how to do this)
insert a new item into one of the tables INSIDE of SolvedMysteries (don’t know how to do this)
… and then save the SolvedMysteries tables again with the new item inside it. (would know how to do this if I knew how to do the second one)

I tried to come up with some code for this, didn’t really do well:

mystery.Solved:Connect(function(plr) -- THIS IS AN IMAGINARY EVENT THAT IS FIRED WHEN THEY SOLVE THE MYSTERY

local success, SolvedMysteries = pcall(function()
return mydatastore:GetAsync(plr.UserId)
end)
tabl = SolvedMysteries.PlaceOne -- or, the .PlaceOne could be any place I need
table.Insert(tabl, "NameOfMystery")
SolvedMysteries.PlaceOne = tabl 
mydatastore:SetAsync(plr.UserId, SolvedMysteries)


end)

I am sure there is an issue with my code AND a much more simple way to complete. Please just tell me what the issue is and how to fix it.

You should be able to fix this by using unpack. However, a better solution would be to loop through the table and utilize table.insert to move each old value into the new table.

1 Like