BoolValue is not saved in DataStoreService

Hello, I have had a recent problem and is that i can not save a BoolValue in a DataStoreService, i have seen several tutorials and nothing, i leave you the script that is in ServerScriptService.

--// VARS \\--
local DataStore = game:GetService("DataStoreService")
local plrData = DataStore:GetDataStore('PlayerSettingsSave')

--// FUNCTIONS \\--
local function onPlayerJoin(plr)
	local folder = Instance.new('Configuration')
	folder.Name = "PlayerSettingsData"
	folder.Parent = plr
	
	local Bool1 = Instance.new('BoolValue')
	Bool1.Name = "LowGraphics"
	Bool1.Parent = folder
	
	local plrUserID = 'Player_'..plr.UserId
	local data = plrData:GetAsync(plrUserID)
	
	if data ~= nil then
		Bool1.Value = plrData[1]
		print("Data was found for "..plr.Name.." ("..plrUserID..")")
	else
		Bool1.Value = false
		print("New player")
	end
end

local function onPlayerLeft(plr)
	local plrUserID = 'Player_'..plr.UserId
	
	local success, err = pcall(function()
		plrData:SetAsync(plrUserID, plr.PlayerSettingsData.LowGraphics.Value)
	end)
	if success then
		print("Saved settings for "..plr.Name.." ("..plrUserID..")")
	else
		warn("Error while trying to save settings for "..plr.Name.." ("..plrUserID..")")
	end
end

--// PLAYER FUNCTION \\--
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeft)

Any help is appreciated!

When saving you need to add the values to a table and save the table itself. Currently you are just saving a boolean.

It did not work, the boolvalue is still false. But thanks for your help

Could you show your what your updated script looks like?

Sure

--// VARS \\--
local DataStore = game:GetService("DataStoreService")
local plrData = DataStore:GetDataStore('PlayerSettingsSave')

--// FUNCTIONS \\--
local function onPlayerJoin(plr)
	local folder = Instance.new('Configuration')
	folder.Name = "PlayerSettingsData"
	folder.Parent = plr
	
	local Bool1 = Instance.new('BoolValue')
	Bool1.Name = "LowGraphics"
	Bool1.Parent = folder
	
	local data = plrData:GetAsync(plr.UserId)
	
	if data ~= nil then
		Bool1.Value = data
		print(Bool1.Value)
		print("Data was found for "..plr.Name.." ("..plr.UserId..")")
	else
		Bool1.Value = false
		print("New player")
	end
end

local function onPlayerLeft(plr)	
	local save = {}
		
	table.insert(save, plr.PlayerSettingsData.LowGraphics.Value)
		
	plrData:SetAsync(plr.UserId, save)
end

--// PLAYER FUNCTION \\--
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeft)

And it also got stuck on true so i dont know how to change it to false because it stays on true.

For this, data is a table so you’d do Bool1.Value = data[1]

Yes i noticed that, i corrected it and nothing, it stays stuck in true.

You sure the value is false when saving? Could you try printing what save is when the player leaves?

I get this

[-] Player maxisepYT has left the game  -  Server
▼  {
     [1] = true
     }  -  Server

Looks like it’s saving correctly then. Are you sure you’re setting the value to false on the server?

I see, now it works without problems, thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.