I want to save a bunch of bool values (true or false) inside of a folder called “Codes”.
The problem is that my character spawns with them already true, even before using them.
I’m using datastore2.
PlayerData, Codes and the datastore Key are defined above this block of code
local ds2 = require(game.ServerStorage.DataStore2)
local Codes = require(game.ServerStorage.Codes)
local default_usage = false
local function createCodes(parent)
for i = 1, #Codes do
local code = Instance.new("BoolValue")
code.Name = Codes[i].code
code.Parent = parent
end
end
game.Players.PlayerAdded:Connect(function(plr)
local codeDataStore = ds2("Codes", plr)
createCodes(plr.PlayerData.Codes)
local function updateCodes(value)
for i, v in pairs(plr.PlayerData.Codes:GetChildren()) do
v.Value = value
end
end
for i = 1, #Codes do
updateCodes(codeDataStore:Get(default_usage)) --this line is specifically problematic
end
codeDataStore:OnUpdate(updateCodes)
end)
--module script
local Codes = {
{
code = "yeeet";
reward = 500
}
}
return Codes
Thank you!