RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a datastore that saves a Bool value called Knight inside the player"
-- server script local DataStoreService = game:GetService("DataStoreService") local KnightDataStore = DataStoreService:GetDataStore("KnightData") local function onSave(player) local success, err = pcall(function() local knightValue = player:FindFirstChild("Knight") if knightValue then KnightDataStore:SetAsync(player.UserId, knightValue.Value) end end) if not success then warn("Failed to save data for " .. player.Name .. ": " .. tostring(err)) end end local function onLoad(player) local success, err = pcall(function() local data = KnightDataStore:GetAsync(player.UserId) if data then local knightValue = Instance.new("BoolValue") knightValue.Name = "Knight" knightValue.Value = data knightValue.Parent = player end end) if not success then warn("Failed to load data for " .. player.Name .. ": " .. tostring(err)) end end game.Players.PlayerAdded:Connect(onLoad) game.Players.PlayerRemoving:Connect(onSave)