Advertisement
Sungmingamerpro13

My New Leaderstats Lobby

Jan 4th, 2025 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.84 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveCurrency = game:GetService("DataStoreService"):GetDataStore("Rounds")
  3. local SaveCurrency2 = game:GetService("DataStoreService"):GetDataStore("Wins")
  4. local SavesCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SavesCurrency4 = game:GetService("DataStoreService"):GetDataStore("Lives")
  6. local SaveRole = game:GetService("DataStoreService"):GetDataStore("Role")
  7. local SaveTags = game:GetService("DataStoreService"):GetDataStore("Tag")
  8.  
  9. game.Players.PlayerAdded:Connect(function(player)
  10.     local Folder = Instance.new("Folder",player)
  11.     Folder.Name = "leaderstats"
  12.  
  13.     local Currency = Instance.new("NumberValue",Folder)
  14.     Currency.Name = "Rounds"
  15.     Currency.Value = SaveCurrency:GetAsync(player.UserId) or 0
  16.  
  17.     local Currency2 = Instance.new("NumberValue",Folder)
  18.     Currency2.Name = "Wins"
  19.     Currency2.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  20.    
  21.     local Currency3 = Instance.new("NumberValue",player)
  22.     Currency3.Name = "Coins"
  23.     Currency3.Value = SavesCurrency3:GetAsync(player.UserId) or 0
  24.    
  25.     local Currency4 = Instance.new("NumberValue",player)
  26.     Currency4.Name = "Lives"
  27.     Currency4.Value = SavesCurrency4:GetAsync(player.UserId) or 0
  28.  
  29. end)
  30.  
  31. game.Players.PlayerRemoving:Connect(function(player)
  32.     SaveCurrency:SetAsync(player.UserId,player.leaderstats.Rounds.Value)
  33.     SaveCurrency2:SetAsync(player.UserId,player.leaderstats.Wins.Value)
  34.     SavesCurrency3:SetAsync(player.UserId,player.Coins.Value)
  35.     SavesCurrency4:SetAsync(player.UserId,player.Lives.Value)
  36. end)
  37.  
  38. game.Players.PlayerAdded:Connect(function(player)
  39.  
  40.     local PreviousData = SaveTags:GetAsync(player.UserId)
  41.     local Tag
  42.     local previousData2 = SaveRole:GetAsync(player.UserId)
  43.     local Role
  44.  
  45.     if PreviousData ~= nil then
  46.         Tag = PreviousData
  47.     else
  48.         Tag = player.Tag.Value
  49.     end
  50.    
  51.     if previousData2 ~= nil then
  52.         Role = previousData2
  53.     else
  54.         Role = player.Role.Value
  55.     end
  56.  
  57.     local TagValue = Instance.new("StringValue", player)
  58.     TagValue.Name = "Tag"
  59.     TagValue.Value = Tag
  60.    
  61.     local RoleValue = Instance.new("StringValue", player)
  62.     RoleValue.Name = "Role"
  63.     RoleValue.Value = Role
  64.  
  65. end)
  66.  
  67. game:BindToClose(function()
  68.     for i,player in pairs(game.Players:GetPlayers()) do
  69.         local value = player.Tag.Value
  70.         SaveTags:SetAsync(player.UserId, value)
  71.         local value2 = player.Role.Value
  72.         SaveRole:SetAsync(player.UserId, value2)
  73.         print("Saved data for "..player.Name)
  74.     end
  75. end)
  76.  
  77. game.Players.PlayerRemoving:Connect(function(player)
  78.     local value = player.Tag.Value
  79.     local value2 = player.Role.Value
  80.    
  81.     if value ~= nil then
  82.         print("Found data to save for "..player.Name.."!")
  83.         SaveTags:SetAsync(player.UserId, value)
  84.         SaveRole:SetAsync(player.UserId, value2)
  85.         print("Saved data for "..player.Name)
  86.     else
  87.         print("Did not manage to find data to save for "..player.Name.."!")
  88.     end
  89. end)
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement