I’m trying to save a folder of boolean values. And then load all those values when the player joins the game.
My current script: – it doesn’t seem to work for some items, wont load the data properly. Any idea what I’m doing wrong? Basically I have bool values, “Item1”, “Item2”, “Powerup1”, “Powerup2” etc…And they are stored in a folder. I just want to load those values when the player joins.
local DataStore = game:GetService("DataStoreService"):GetDataStore("FolderDataTest")
print("Ran data store")
local folderChildren = {
"Stars",
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
"Item6",
"Item7",
"Item8",
"Item9",
"Pet1",
"Pet2",
"Powerup1",
"Powerup2"
}
game.Players.PlayerAdded:Connect(function(player)
local folder = player:WaitForChild("PlayerData")
local savedValues = DataStore:GetAsync("FolderValues")
if savedValues then
for _, child in ipairs(folder:GetChildren()) do
for i, childName in ipairs(folderChildren) do
if child.Name == childName then
child.Value = savedValues[i]
break
end
end
end
else
warn("Failed to load data for player " .. player.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local folder = player:WaitForChild("PlayerData")
local values = {}
for _, child in ipairs(folder:GetChildren()) do
for i, childName in ipairs(folderChildren) do
if child.Name == childName then
values[i] = child.Value
break
end
end
end
DataStore:SetAsync("FolderValues", values)
end)