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.MouseButton1Up:Connect(function()
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
end
else
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."
end
end)
This script reads it:
local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(plr)
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)
end)
if not success then
warn(errorMessage)
end
if success then
print(plr.UserId)
end
else
print("pass = false")
end
end)
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")
Players.PlayerAdded:Connect(function(plr)
local success, value = pcall(function()
return passStore:GetAsync(plr.UserId)
end)
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
else
pass.Value = false
end
end)
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.
firePassed.OnServerEvent:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local passBool = leaderstats and leaderstats:FindFirstChild("Pass")
if passBool then
passBool.Value = true
print("passBool changed")
else
print("Cant find passBool")
end
end)
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.