I'm having trouble changing a BoolValue

I have a script that changes a BoolValue of a player and then another script reads it, but the other script doesn’t see it as changed.
This script changes it:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local testingScreen = playerGui:WaitForChild("TestingScreen")
local testingFrame = testingScreen.TestingFrame

local statsFolder = player:WaitForChild("leaderstats")
local pass = statsFolder and statsFolder:FindFirstChild("Pass")

local question10 = testingFrame.Question10
local qTenOption1 = question10.Option1
local qTenOption2 = question10.Option2
local qTenOption3 = question10.Option3
local qTenOption4 = question10.Option4
local qTenQuestion = question10.QuestionInstructions

local applicationResults = testingFrame.EndingSequence.ApplicationResults

local correctAnswers = {}

	qTenOption1.Visible = false
	qTenOption2.Visible = false
	qTenOption3.Visible = false
	qTenOption4.Visible = false
	qTenQuestion.Visible = false
	applicationResults.Visible = true
	table.insert(correctAnswers, "Question10")
	if #correctAnswers == 10 then
		applicationResults.Text = "Congratulations!!! You have passed the Antarctic Eats Application! Within the next 24 hours, you will be ranked to trainee. You can now clean to earn points, but you can't do anything else. To become a chef, look for the next training in the calendar in the handbook and go to it. Good luck! You may now leave."
		if pass then
			pass.Value = true
		applicationResults.Text = "Unfortunately, you have missed one or more questions, so you have failed. I suggest reading over the handbook and trying again. You may now leave."

This script reads it:

local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")

local Players = game:GetService("Players")

	print("plr removing")
	local statsFolder = plr:WaitForChild("leaderstats")
	local pass = statsFolder and statsFolder:FindFirstChild("Pass")
	if pass == true then
		local success, errorMessage = pcall(function()
			passStore:UpdateAsync(plr.UserId, true)
		if not success then 
		if success then
		print("pass = false")

How can I fix this?

This is because this is a server script while the other one is a Local script.

I tried using remote events to change the bool value on the server side, and it still didn’t work.

Did it give any errors???

No, it didn’t give any errors. It just said the BoolValue was false.

It did change, On the Server though.
Did you add the BoolValue manually?

I don’t think it changed on the server, only the client. The BoolValue is added through this server side script:

local Players = game:GetService("Players")

local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")

	local success, value = pcall(function()
		return passStore:GetAsync(plr.UserId)
	local statsFolder = Instance.new("Folder")
	statsFolder.Name = "leaderstats"
	statsFolder.Parent = plr
	local pass = Instance.new("BoolValue")
	pass.Name = "Pass"
	pass.Parent = statsFolder
	if success then
		pass.Value = value
		pass.Value = false

Ok, I see
Can you add a RemoteEvent and fire the pass value with it then print ?

So fire it from the client then change it on the server? I already tried this in the script I showed in my previous reply, but I can try adding it in another script.

Yeah do that but add a Print On The Server when its fired.

I added this function:

	local leaderstats = plr:WaitForChild("leaderstats")
	local passBool = leaderstats and leaderstats:FindFirstChild("Pass")
	if passBool then
		passBool.Value = true
		print("passBool changed")
		print("Cant find passBool")

Before the Players.PlayerRemoving function on the server script, and it printed passBool changed

Okay, So it basically works on the Server
Can you tell me what do you need to do?
Do You want to make it Save even after the Player Leaves?
If so then When the Player joins (check his data) then fire a RemoteEvent with from the Server-Client Making the BoolValue set to true.

Yes, I want to make it save even after the player leaves. I don’t think the problem is with setting the data after the player rejoins, but with actually saving it.

I tried again changing it on the server using a completely new script, and it still won’t work. It says the value was changed, but in the other script, it said it was still false.

Are you giving it time to update, try adding a wait()
Remember to rem pcalls to see if they are erroring
Did you try following the logs …
See if passStore:SetAsync is working …
Go look if the value did change …to true

It’s not a problem with the data stores. In the second script, it printed pass = false, meaning it thinks the boolValue is false. I even checked if it was nil, not false, and it still said it was false.

@2112Jay @lilmazen1234 I found the issue! When I was checking if pass was true, I used pass, not pass.Value. This is why it wasn’t working.

Dang … I seen that too I was wondering why that looked odd.

1 Like