Database problem yet again

I previously made this forum:

The script did work for a while, but now for some reason it does not work anymore.

Any reasons why?

Here’s the code:

local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")

local function onPlayerJoin(Player)
	local BlackMarketThings = Instance.new("Folder")
	BlackMarketThings.Name = "BlackMarketThings"
	BlackMarketThings.Parent = Player

	local SpeedCheck = Instance.new("BoolValue")
	SpeedCheck.Name = "SpeedCheck"
	SpeedCheck.Parent = BlackMarketThings
	SpeedCheck.Value = false

	local playerUserId = "Player_ ".. Player.UserId
	local data = playerData:GetAsync(playerUserId)
	if data then
		SpeedCheck.Value = data and data.SpeedCheck
	else
		SpeedCheck.Value = false
	end
end

local function onPlayerLeave(Player)
	local success, err = pcall(function()
		local playerUserId = "Player_ "..Player.UserId
		local speedCheckValue = Player.BlackMarketThings.SpeedCheck.Value

		local dataToSave = {
			SpeedCheck = speedCheckValue
		}
		playerData:SetAsync(playerUserId, dataToSave)

	end)
	if not success then
		warn("Could not save data, Error message: ", err)
	else
		print("Saved 2")
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeave)

Shouldn’t this just be SpeedCheck.Value = data.SpeedCheck?

Also, in which part is the code not working? Does it not save or does it not load?

The code will still not work

I think the code would not load, the script would still display “saving 2” when I close the game

No, since doing data and before assigning it makes sure the data exists before trying to get any attributes. If the player’s data was nil, SpeedCheck.Value = data.SpeedCheck would give an error, stating that it cant find missing attribute SpeedCheck of nil
With the addition, if data is nil, it sets SpeedCheck.Value to false instead of giving an error.

still find it weird that it worked before, but then it just magically stops working