RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a script that save an existing bool value inside the player"
-- server script local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("PlayerBoolData") local function onSave(player) local success, err = pcall(function() local boolValue = player.BoolValue.Value myDataStore:SetAsync(player.UserId.."_boolValue", boolValue) end) if not success then warn("Failed to save data for " .. player.Name .. ": " .. err) end end local function onPlayerAdded(player) local success, err = pcall(function() local savedBoolValue = myDataStore:GetAsync(player.UserId.."_boolValue") if savedBoolValue then local boolValue = Instance.new("BoolValue") boolValue.Name = "BoolValue" boolValue.Value = savedBoolValue boolValue.Parent = player else local boolValue = Instance.new("BoolValue") boolValue.Name = "BoolValue" boolValue.Value = false boolValue.Parent = player end end) if not success then warn("Failed to load data for " .. player.Name .. ": " .. err) end player.CharacterRemoving:Connect(function() onSave(player) end) end game.Players.PlayerAdded:Connect(onPlayerAdded) game.Players.PlayerRemoving:Connect(onSave)