Error: UserId is not a valid member of BoolValue "ReplicatedStorage.BonfireReplicated.player_data.1553836878.bonfires.bonfire 1"
Code:
local import = require(game:GetService("ReplicatedStorage"):WaitForChild("BonfireReplicated"):WaitForChild("import"))
-- const
local Services = import("shared/services")
local PlayerData = import("player_data")
local Datastore = Services.DataStoreService:GetDataStore("PlayerData")
-- functions
local function LoadData(player)
local dataFolder = script.data_folder:Clone()
dataFolder.Name = player.UserId
local saveData = Datastore:GetAsync(player.UserId)
if saveData then
if saveData.last_bonfire then
dataFolder.last_bonfire.Value = saveData.last_bonfire
end
if saveData.bonfires then
for _, b in pairs(saveData.bonfires) do
local bonfire = Instance.new("BoolValue")
bonfire.Name = b
bonfire.Parent = dataFolder.bonfires
end
end
end
dataFolder.Parent = PlayerData
return dataFolder
end
local function SaveData(player)
local playerData = PlayerData:FindFirstChild(player.UserId)
if not playerData then
return
end
local saveData = {
last_bonfire = playerData.last_bonfire.Value;
bonfires = {};
}
for _, b in pairs(playerData.bonfires:GetChildren()) do
table.insert(saveData.bonfires, b.UserId)
end
Datastore:SetAsync(player.UserId)
end
-- events
Services.Players.PlayerAdded:Connect(function(player)
LoadData(player)
end)
Services.Players.PlayerRemoving:Connect(function(player)
SaveData(player)
local dataFolder = PlayerData:FindFirstChild(player.UserId)
if dataFolder then
dataFolder:Destroy()
end
end)