Saving and loading bool value leaderstats not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    want to saving and load bool values to a player so that when all bool values are set to true a script to do an action.
  2. What is the issue? Include screenshots / videos if possible!
    Doesnt appear to saving on exit although there is no error API and http:// enabled in studio
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    tried different script versions
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

THIS SCRIPT IS FROM THIS SITE however i can not get it to work although there appear to be no error in the output.

local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“MoneyStatus”)

game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats2 = Instance.new(“Folder”, Player)
Leaderstats2.Name = “leaderstats2”
local V1 = Instance.new(“BoolValue”, Leaderstats2)
V1.Name = “Achievement1”
local V2= Instance.new(“BoolValue”, Leaderstats2)
V2.Name = “Achievement2”
local V3 = Instance.new(“BoolValue”, Leaderstats2)
V3.Name = “Achievement3”

local Data = DataStore:GetAsync(Player.UserId)
if Data then
	V1.Value = Data.Achievement1
	V2.Value = Data.Achievement2
	V3.Value = Data.Achievement3
end

end)

game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId,{
[“Achievement1”] = Player.leaderstats2.Achievement1.Value;
[“Achievement2”] = Player.leaderstats2.Achievement2.Value;
[“Achievement3”] = Player.leaderstats2.Achievement3.Value;
})
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Do you have Access to API services enabled?
image

Hi mate yes i do have the API selected on as well as http request. it is strange the bool value are there you can manually select them to true in studio however if you leave and re join the do nt remember they where selected to true they all go back to false.

Have also tried this version with the same result :slight_smile:

local DataStoreService = game:GetService(“DataStoreService”)

local myDataStore = DataStoreService:GetDataStore(“myDataStore”)

game.Players.PlayerAdded:Connect(function(player)
local leaderstats2 = Instance.new (“Folder”)
leaderstats2.Name = “leaderstats2”
leaderstats2.Parent = player

local stage1 = Instance.new("BoolValue")
stage1.Name  = "stage1"
stage1.Parent = leaderstats2

local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId…"-stage1")

end)

if success then
stage1.Value = data
print(“data successfully loaded”)
else
print("there was an error ")
warn (“error message”)
end
end)

game.Players.PlayerRemoving:Connect(function(player)

local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-stage1",player.leaderstats2.stage1.Value)
end)	

if success then 
	print ("player data successfully saved")
else
	print( "there was an error saving ")
	warn ("there was a save error")
end
end)
1 Like

You can’t save bool values on DataStore1, use a number value and if the value is 0 is false and if is 1 is true.

Hi Mate thank you for your help however I am a bit of a novice can you expain what you mean in regards to addapting a number value to this script? thank you

HI tried changing the bool value to a number value however it still does not save if you change the number value manually to a 1 not a 0 once you exit and re enter the game it will change bac to a 0 Maybe I am entering something incorrectly?

Can you tell me what appears within your output log?

Capture

This is from the second script in a new place with only the datastore script in it nothing else. It is strange as othere games i have normal gems or coins are not an issue and always save as intended. thanks you again for your help

1 Like

I found why its wasnt working it you manually change the number value to 1 in studio it doesnt save if you change the value with a part or gui it does retain the number thank you for your help

Well, that would be a client-side edit the server wouldn’t see what you have done. Unless you clicked to switch to server before changing the values.