Saving Boolean Value with GlobalDataStore

  1. What do you want to achieve? Keep it simple and clear!
    I would like to save a Boolean value to the datastore

  2. What is the issue? Include screenshots / videos if possible!
    The Boolean value dos not save whilst the other values DO save

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have looked at 1 other post with instructions to fix, it said to tostring() one of the code blocks, the code block mentioned was not clarified

This is the datastore script with the leader stats management stuff

local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
game.Players.PlayerAdded:Connect(function(plr)
	--create a leaderstats folder for the player
	local userMapInfo = Instance.new("Folder")
	userMapInfo.Name = "userMapInfo"
	userMapInfo.Parent = plr

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	--add a new leaderstat named wins
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Value = 0
	wins.Parent = leaderstats

	local map1Comp = Instance.new("BoolValue")
	map1Comp.Name = "Map1 Completion"
	map1Comp.Value = false
	map1Comp.Parent = userMapInfo

	wait()
	local plrkey = "id_"..plr.UserId
	local save1 = plr.leaderstats.Wins
	local save2 = plr.userMapInfo["Map1 Completion"]

	local Saved = ds:GetAsync(plrkey)
	if Saved then
		save1.Value = Saved[1]
		save2.Value = Saved[2]
	else
		local NumberForSaving = {save1.Value, save2.Value}
		ds:GetAsync(plrkey, NumberForSaving)
	end






end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Wins.Value,  plr.userMapInfo["Map1 Completion"].Value})
end)



The leaderstat scripts is the EXACT same in the second place.

Here is a screenshot of the player’s leaderstats and other values to make visualizing easier:
image

1 Like

I tried your code on another place and slightly modified it so that it changes the values, and it works just fine. Do you have any scripts that might conflict with this code and have you checked for any errors in the Output window?

Tested place in question:
Saving_Boolean_Value_with_GlobalDataStore.rbxl (45.3 KB)

1 Like

No errors appear, the only other code I have is code that manages screenGUI and frame visibility and button clicking management but that is it.

1 Like

I’ve changed the BooleanValue to a IntValue and it does not work either which makes me wonder if datastore can only get and save from leaderstats?