Advertisement
Sungmingamerpro13

My SaveRoles leaderstats Lobby

Sep 2nd, 2024
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.85 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveRoles = game:GetService("DataStoreService"):GetDataStore("Role")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.    
  6.     local  Role = Instance.new("StringValue", player)
  7.     Role.Name = "Role"
  8.     Role.Value = player.Role.Value
  9.    
  10. end)
  11.  
  12. game:BindToClose(function()
  13.     for i,player in pairs(game.Players:GetPlayers()) do
  14.         local value = player.Role.Value
  15.         SaveRoles:SetAsync(player.UserId, value)
  16.         print("Saved data for "..player.Name)
  17.     end
  18. end)
  19.  
  20. game.Players.PlayerRemoving:Connect(function(player)
  21.     local value = player.Role.Value
  22.  
  23.     if value ~= nil then
  24.         print("Found data to save for "..player.Name.."!")
  25.         SaveRoles:SetAsync(player.UserId, value)
  26.         print("Saved data for "..player.Name)
  27.     else
  28.         print("Did not manage to find data to save for "..player.Name.."!")
  29.     end
  30. end)
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement