Data Storage Issues Scripting Support

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)

I stopped coding for 2 years and came back. And i have forgotten how to code and read errors. I’ve tried searching up for solutions but there were none.

It looks like your reading through a Folder with a bunch of BoolValues try replacing b.UserId with b.Value.

Argument 2 missing or nil - Server
08:26:24.745 Stack Begin - Studio
08:26:24.745 Script ‘ServerScriptService.data_script_server’, Line 55 - function SaveData - Studio
08:26:24.745 Script ‘ServerScriptService.data_script_server’, Line 65 - Studio
08:26:24.745 Stack End - Studio

before this one i got

08:24:33.423 Infinite yield possible on ‘ReplicatedStorage.BonfireReplicated.player_data:WaitForChild(“1553836878”)’ - Studio
08:24:33.424 Stack Begin - Studio
08:24:33.424 Script ‘ReplicatedStorage.BonfireReplicated.import’, Line 9 - function import - Studio - import:9
08:24:33.424 Script ‘ServerScriptService.bonfire_script_server’, Line 77 - Studio - bonfire_script_server:77
08:24:33.424 Stack End - Studio

This already has been fixed by me. Because i made some mistakes while creating the code.

Thank you to everyone who tried to help me before!