Sungmingamerpro13

leaderstats styled Grimmy Story (Main)

Jun 8th, 2026
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.75 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 PreviousData = SaveRoles:GetAsync(player.UserId)
  7.     local Role
  8.  
  9.     if PreviousData ~= nil then
  10.         Role = PreviousData
  11.     else
  12.         Role = script.Role.Value
  13.         SaveRoles:SetAsync(player.UserId, Role)
  14.     end
  15.  
  16.     local RoleValue = Instance.new("StringValue", player)
  17.     RoleValue.Name = "Role"
  18.     RoleValue.Value = Role
  19.  
  20.     player:WaitForChild("Role"):GetPropertyChangedSignal("Value"):Connect(function()
  21.         player.Role.Value = player.Role.Value
  22.     end)
  23.  
  24. end)
  25.  
  26. game:BindToClose(function()
  27.     for i,player in pairs(game.Players:GetPlayers()) do
  28.         local value = player.Role.Value
  29.         SaveRoles:SetAsync(player.UserId, value)
  30.         print("Saved data for "..player.Name)
  31.     end
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(player)
  35.     local value = player.Role.Value
  36.  
  37.     if value ~= nil then
  38.         print("Found data to save for "..player.Name.."!")
  39.         SaveRoles:SetAsync(player.UserId, value)
  40.         print("Saved data for "..player.Name)
  41.     else
  42.         print("Did not manage to find data to save for "..player.Name.."!")
  43.     end
  44. end)
  45.  
  46. local CashDataStore = game:GetService("DataStoreService"):GetDataStore("Cash")
  47. local GemsDataStore = game:GetService("DataStoreService"):GetDataStore("Gems")
  48.  
  49. game.Players.PlayerAdded:Connect(function(player)
  50.     local previousData = CashDataStore:GetAsync(player.UserId)
  51.     local previousData2 = GemsDataStore:GetAsync(player.UserId)
  52.    
  53.     local Cash
  54.     local Gems
  55.    
  56.     if previousData ~= nil then
  57.         Cash = previousData
  58.     else
  59.         Cash = 0
  60.         CashDataStore:SetAsync(player.UserId, Cash)
  61.     end
  62.    
  63.     if previousData2 ~= nil then
  64.         Gems = previousData2
  65.     else
  66.         Gems = 0
  67.         GemsDataStore:SetAsync(player.UserId, Gems)
  68.     end
  69.  
  70.     local CashValue = Instance.new("NumberValue", player)
  71.     CashValue.Name = "Cash"
  72.     CashValue.Value = Cash
  73.    
  74.     local gemsValue = Instance.new("NumberValue", player)
  75.     gemsValue.Name = "Gems"
  76.     gemsValue.Value = Gems
  77.    
  78. end)
  79.  
  80. game:BindToClose(function()
  81.     for i,player in pairs(game.Players:GetPlayers()) do
  82.         local value = player.Cash.Value
  83.         local value2 = player.Gems.Value
  84.        
  85.         CashDataStore:SetAsync(player.UserId, value)
  86.         GemsDataStore:SetAsync(player.UserId, value2)
  87.        
  88.         print("Saved data for "..player.Name)
  89.     end
  90. end)
  91.  
  92. game.Players.PlayerRemoving:Connect(function(player)
  93.     local value = player.Cash.Value
  94.     local value2 = player.Gems.Value
  95.    
  96.     if value ~= nil then
  97.         print("Found data to save for "..player.Name.."!")
  98.         CashDataStore:SetAsync(player.UserId, value)
  99.         GemsDataStore:SetAsync(player.UserId, value2)
  100.        
  101.         print("Saved data for "..player.Name)
  102.     else
  103.         print("Did not manage to find data to save for "..player.Name.."!")
  104.     end
  105. end)
  106.  
Advertisement
Add Comment
Please, Sign In to add comment