Hello, i made a bool value saving system but it somehow does not works. Everything works well but it does not save the data when player leaves. With prints it prints "Trying to save data" but then nothing and nothing works.
local service = game:GetService("DataStoreService")
local dataStore = service:GetOrderedDataStore("BoolValueDataStore")
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("IntValue",player)
stats.Name = "BoolValues"
local doorOpen = Instance.new("BoolValue", stats)
doorOpen.Name = "DoorOpen"
doorOpen.Value = false
local data
local success = pcall(function()
data = dataStore:GetAsync(player.UserId,doorOpen.Value)
end)
if success then
doorOpen.Value = data
print("data restored")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
print("trying to save data")
dataStore:SetAsync(player.UserId, player.BoolValues.DoorOpen.Value)
print("data saved")
end)
end)

6 comments
code blocks pls
Oh thanks for that tho i always thought it is automatical,
remove the extra argument of "GetAsync()" as it only requires the player's key.
Thanks i have done that but still, line 23 does not work.
pcalls safely call functions so they don't stop the thread when they error which is why you have to do something like "local success, err = pcall(function() -- save data blahbahbhabha end) if not success then error(err) end" to get any results.
Yes thanks a lot this is exactly what i needed or i mean by that i have found what the problem is in, you cannot save bool into ordered DataStore so instead of that you just have to use :GetDataStore() . Thanks you all for help i really appreciate it!