Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService") -- Getting The Main Service
- local Players = game:GetService("Players") -- Getting This Service For Connecting Events For A Player
- local DataStore = DataStoreService:GetDataStore("1") -- If You Change This 1 To Another Number, All Data Will Be Reset
- Players.PlayerAdded:Connect(function(player: Player) -- Using The PlayerAdded Event
- local data
- local success, errorMsg = pcall(function()
- DataStore:GetAsync(player.UserId.."-points") -- Retrieving The Player's Data With A Specific Key
- end)
- if success then
- data = player.leaderstats.Points.Value -- Setting Data To The Player's Points
- else
- print("There Was An Error Loading "..player.Name.." 'S Data!")
- wait(errorMsg)
- end
- end)
- Players.PlayerRemoving:Connect(function(player: Player) -- Using The PlayerRemoving Event
- local success, errorMsg = pcall(function()
- DataStore:SetAsync(player.UserId.."-points", player.leaderstats.Points.Value) -- Setting A Specific Key For This Stat
- end)
- if success == true then
- print(player.Name.." 'S Data Was Saved!") -- Printing If A Player's Data Was Saved Correctly
- else
- print("There Was An Error Saving "..player.Name.."'S Data!")
- warn(errorMsg)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement