I could swear that I did everything right, its just that my pcall function wont return anything in the output and it is not saving. Take a look
Server Script inside ServerScriptService
I'm trying to save a bool value's value by changing the value then saving it. So the value starts out as true but it changes to false then it is supposed to save.
The objective is to save the value while it is changed to false, so I can rejoin the game and the value stays false for my specific key id. :)
Also I don't test in studio, I always test in the real game.
local DSS = game:GetService("DataStoreService") local DataStore = DSS:GetDataStore("SavePromptValue") game.Players.PlayerAdded:Connect(function(player) local ValueNeedingSaving = player:WaitForChild("ValueNeedingSaving",1) -- this bool value is cloned into the player through a different script. It is set to true originally ValueNeedingSaving.Value = DataStore:GetAsync(player.UserId) or true -- Loading the value's value from last saved(since the start value is true, I am returning it to true again instead of false) if ValueNeedingSaving.Value == false then print("it worked!") else ValueNeedingSaving.Value = false -- this changes the value to false if it isn't already, so we only want to get this message once print("Either you are changing the value for the first time, or it didn't work") end local success, err = pcall(function() DataStore:SetAsync(player.UserId, ValueNeedingSaving.Value) end) if success then print("Data successfully saved") -- this isn't printing in the output end if err then print("There were some issues while saving the data") -- this is also not saving so Im confused end end)
Thanks to pidgey
, he helped me figure out the answer! heres the code:
local DSS = game:GetService("DataStoreService") local DataStore = DSS:GetDataStore("SavePromptValue") game.Players.PlayerAdded:Connect(function(player) local ValueNeedingSaving = player:WaitForChild("ValueNeedingSaving",1) -- this bool value is cloned into the player through a different script. It is set to true originally ValueNeedingSaving.Value = DataStore:GetAsync(player.UserId) and nil and true and DataStore:GetAsync(player.UserId) -- Loading the value's value from last saved(since the start value is true, I am returning it to true again instead of false) if ValueNeedingSaving.Value == false then print("it worked!") else ValueNeedingSaving.Value = false -- this changes the value to false if it isn't already, so we only want to get this message once print("Either you are changing the value for the first time, or it didn't work") end local success, err = pcall(function() DataStore:SetAsync(player.UserId, ValueNeedingSaving.Value) end) if success then print("Data successfully saved") -- this isn't printing in the output end if err then print("There were some issues while saving the data") -- this is also not saving so Im confused end end)