BoolValue datastore not working/scripts that check if it works not working

So i have this script which is suppost to save a boolvalues value

local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder", plr)
	Folder.Name = "test"
	local BoolValue = Instance.new("BoolValue", Folder)
	BoolValue.Name = "BoolValue"
	local BoolValue2 = Instance.new("BoolValue", Folder)
	BoolValue2.Name = "BoolValue2"
	print("BoolValues succesfully created!")

	local dataofuser = ds:GetAsync(plr.UserId)
	if dataofuser then
		BoolValue.Value = dataofuser[1] 
		BoolValue2.Value = dataofuser[2]
	else
		print("Replacing no data with new data.")
		BoolValue.Value = false
		BoolValue2.Value = false
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {plr:WaitForChild("test"):WaitForChild("BoolValue").Value, plr:WaitForChild("test"):WaitForChild("BoolValue2").Value}

	local success, response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("Successfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)

im not sure if it works, but i also have these scripts:



game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character
	if not char then
		char = plr.CharacterAdded:Wait()
	end

	local hum = char:FindFirstChildOfClass("Humanoid")
	if hum then
		local testFolder = plr:FindFirstChild("test")
		if testFolder then
			local boolValue = testFolder:FindFirstChild("BoolValue")
			if boolValue and boolValue:IsA("BoolValue") then
				if boolValue.Value == true then
					hum.WalkSpeed = 20
				else
					print("Player's BoolValue isn't set to true!")
				end
			else
				print("BoolValue not found in 'test' folder for player.")
			end
		else
			print("Test folder not found for player.")
		end
	else
		print("Humanoid not found for player.")
	end
end)

also this

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character
	if not char then
		char = plr.CharacterAdded:Wait()
	end

	local hum = char:FindFirstChildOfClass("Humanoid")
	if hum then
		local testFolder = plr:FindFirstChild("test")
		if testFolder then
			local boolValue = testFolder:FindFirstChild("BoolValue2")
			if boolValue and boolValue:IsA("BoolValue") then
				if boolValue.Value == true then
					hum.JumpPower = 75
				else
					print("Player's BoolValue isn't set to true!")
				end
			else
				print("BoolValue not found in 'test' folder for player.")
			end
		else
			print("Test folder not found for player.")
		end
	else
		print("Humanoid not found for player.")
	end
end)

to shorten it, im just trying to save the boolvalue so once i purchase a power up in my game, example: 25% more jump power/speed i want it to save the speed, the scripts check if a certain boolvalue is true and if it is then they do the effects a power up is suppost to do, i also have a script that enables the boolvalue.

This is a very important lesson, but think about it, how does the client know its value? How is the server communicating that value across? And how is it saved after it was communicated? I found this out when saving boolvalues myself switching to server mode will tell you if you are updating the value correctly and replicating that to the client correctly, and then lastly you know it saves back to the server correctly.

Edit: I don’t know if that was clear but to get this working (correctly) is to update the boolvalue on the server not just the client side. This involves remote events, once both sides know the value and you save it you should be fine.
I also don’t even think you have it labeled right.

	local BoolValue = Instance.new("BoolValue", Folder)
	BoolValue.Name = "BoolValue"
        BoolValue = false

	local BoolValue2 = Instance.new("BoolValue", Folder)
	BoolValue2.Name = "BoolValue2"
        BoolValue = false

I would first set them to false, then when I wanted to modify it i’d use a remote event.
This example uses profile service

local function ChangeBoolValue(player)
	local profile = PlayerData.Profiles[player]
	if not profile then return end
	
	profile.Data.BoolValues[testbool1] = true
	Remotes.UpdateBoolValue:FireClient(player, testbool1)
	return "Success"
end

Remotes.ChangeBoolValue.OnServerInvoke = ChangeBoolValue

Of course you named your folder Folder, and you aren’t useing a table to hold your values. But this same concept applies.

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