RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a script inside server script service that will save bool values"
local DataStoreService = game:GetService("DataStoreService") local boolDataStore = DataStoreService:GetDataStore("BoolValuesDataStore") game.Players.PlayerAdded:Connect(function(player) local success, errorMessage = pcall(function() local savedData = boolDataStore:GetAsync(player.UserId) if savedData then -- Load saved bool values for the player for key, value in pairs(savedData) do player:SetAttribute(key, value) end else -- Set default bool values for the player player:SetAttribute("BoolValue1", false) player:SetAttribute("BoolValue2", false) player:SetAttribute("BoolValue3", false) end end) if not success then warn("Failed to load data for player " .. player.Name .. ": " .. errorMessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errorMessage = pcall(function() local dataToSave = {} dataToSave["BoolValue1"] = player:GetAttribute("BoolValue1") dataToSave["BoolValue2"] = player:GetAttribute("BoolValue2") dataToSave["BoolValue3"] = player:GetAttribute("BoolValue3") boolDataStore:SetAsync(player.UserId, dataToSave) end) if not success then warn("Failed to save data for player " .. player.Name .. ": " .. errorMessage) end end) game:BindToClose(function() for _, player in ipairs(game.Players:GetPlayers()) do local success, errorMessage = pcall(function() local dataToSave = {} dataToSave["BoolValue1"] = player:GetAttribute("BoolValue1") dataToSave["BoolValue2"] = player:GetAttribute("BoolValue2") dataToSave["BoolValue3"] = player:GetAttribute("BoolValue3") boolDataStore:SetAsync(player.UserId, dataToSave) end) if not success then warn("Failed to save data for player " .. player.Name .. ": " .. errorMessage) end end end)