Hi! Me and my friend are working with Data Store 2 and we’ve come across an error. Basically we’re trying to make areas save with the player and when they join back the values should be in a folder.
Here is the code ex:
local DataStore = DataStore2(dataStoreName, Player)
local Data = DataStore:Get()
if Data == nil then
DataStore:Set({
Areas = {
Desert = false,
Candy = false,
Lava = false
},
Leaderstats = {
["💰 Coins"] = 0,
["🍲 Soups"] = 0,
["⏰ Time"] = 0
},
Stats = {
MaxIngredients = 50,
Ingredients = 0,
IsInfinite = false,
IngredientMultiplier = 1,
Time = 0,
MaxSoups = 5,
DailyTime = os.time(),
DailyRewardTimer = 43200
},
})
Data = DataStore:Get()
end
Everything works with the data, but the areas table doesn’t. I have the areas name in them and when I try to loop through them, I get nil.
Code:
for StatName, Value in pairs(Data.Areas) do
local StatValue = Instance.new("BoolValue")
StatValue.Name = StatName
StatValue.Value = Value
StatValue.Changed:Connect(function()
local newTable = {}
for _, val in ipairs(lstatFolder:GetChildren()) do
newTable[val.Name] = val.Value
end
local oldn = newTable
newTable = DataStore:Get()
newTable.Areas = oldn
DataStore:Set(newTable)
end)
StatValue.Parent = Area
end
The same code is used for the Leaderstats and the Stats, but not this. I don’t know why it says it’s nil, but if anyone can help us that would be appreciated!