What is the problem?
Heres the code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local PlayerData
local Success, ErrorMsg = pcall(function()
local PlayerId = plr.UserId
PlayerData = Plrdtastore:GetAsync(PlayerId)
end)
local bools = plr.PlayerGui.AttachmentsUpgradesGui.LocalWork.Selected
if Success then
if PlayerData then
- very long list of data store
end
else
warn(ErrorMsg)
end
end)
end)
local function saveData(plr)
local bools = plr:WaitForChild("PlayerGui"):WaitForChild("AttachmentsUpgradesGui").LocalWork.Selected
local PlayerData = {- very long list of data store
}
print(PlayerData)
local Success, ErrorMsg = pcall(function()
Plrdtastore:SetAsync(plr.UserId, PlayerData)
end)
if not Success then
warn(ErrorMsg)
end
end
make a table
local data = {}
for i, bools in pairs do data[i] = bools end
datastore:setasync(data)
3 Likes
Assuming youâre iterating through a folder that contains all of these BoolValues:
local bools = {}
for i, bool in (path.to.boolvalues:GetChildren()) do
bools[bool.Name] = bool.Value
end
-- Say you had a BoolValue whose name was "Created" and whose value was true:
-- Visually, that would look like this:
--[[
bools = {
["Created"] = true
}
]]--
You can then either add this table to existing data:
-- Assuming data is already defined
data["Bools"] = bools -- bools variable from previous example
Or if it is all you need, then you can pass it through SetAsync
.
It prints this?
âtable: 0xaf107e7dddc61d49â
Thatâs expected if youâre checking the Developer Console in a live experience. The output in Studio should allow you to see what is inside of the table you print.
and now, âlocal bools = plr:FindFirstChild(âPlayerGuiâ):FindFirstChild(âAttachmentsUpgradesGuiâ).LocalWork.Selectedâ shows
âattempt to index nil with âFindFirstChildââ