Database problem yet again (repost)

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)

What’s your problem? What isn’t working?

I feel like the script is not loading up the boolean value. The script correctly displays an output saying “Saving 2”.

What do you mean when you say you don’t feel it is loading the value? Is the data being loaded correct?

no the data is not being loaded correctly, sorry about that

This part

SpeedCheck.Value = data and data.SpeedCheck

Change to

SpeedCheck.Value = data.SpeedCheck

There is no problem with that line, infact it is a good practice.

1 Like

He already checked if data exist or not so it’s not necessary to do that.

That’s because in a previous forum post someone misunderstood the line and told him to add another check.

yeah I absolutely suck at database

really?

I think its you that misunderstood what the usage of this is for.