RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Datat store system"
-- DataStore script (ServerScriptService) local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("MyDataStore") game.Players.PlayerAdded:Connect(function(player) local success, data = pcall(function() return myDataStore:GetAsync(player.UserId) end) if success and data then player.leaderstats.Coins.Value = data else player.leaderstats.Coins.Value = 0 end end) game.Players.PlayerRemoving:Connect(function(player) local success, err = pcall(function() myDataStore:SetAsync(player.UserId, player.leaderstats.Coins.Value) end) if not success then warn("Failed to save data for " .. player.Name .. ": " .. err) end end) game:BindToClose(function() for _, player in ipairs(game.Players:GetPlayers()) do local success, err = pcall(function() myDataStore:SetAsync(player.UserId, player.leaderstats.Coins.Value) end) if not success then warn("Failed to save data for " .. player.Name .. ": " .. err) end end end)