Sungmingamerpro13

leaderstats styled Grimmy Story (Lobby)

Jun 8th, 2026
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.24 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveRoles = game:GetService("DataStoreService"):GetDataStore("Role")
  3.  
  4. function determinePlayerRole(player)
  5.    
  6.     local protector = "Protector"
  7.    
  8.     if protector then
  9.         print("Protector assigned to player")
  10.         return "Protector"
  11.     else
  12.         return "Medic"
  13.     end
  14. end
  15.  
  16. game.Players.PlayerAdded:Connect(function(player)
  17.    
  18.     local PreviousData = SaveRoles:GetAsync(player.UserId)
  19.     local Role
  20.  
  21.     if PreviousData ~= nil then
  22.         Role = PreviousData
  23.     else
  24.         Role = script.Role.Value
  25.         SaveRoles:SetAsync(player.UserId, Role)
  26.     end
  27.  
  28.     local RoleValue = Instance.new("StringValue", player)
  29.     RoleValue.Name = "Role"
  30.     RoleValue.Value = Role
  31.  
  32.     player:WaitForChild("Role"):GetPropertyChangedSignal("Value"):Connect(function()
  33.         player.Role.Value = player.Role.Value
  34.     end)
  35.    
  36.     local roleName = determinePlayerRole(player)
  37.    
  38.     if roleName == "Protector" then
  39.         print("The Protector")
  40.     else
  41.         print("The Medkit")
  42.     end
  43.    
  44.     local teleportOptions = Instance.new("TeleportOptions")
  45.     local teleportData = {
  46.         Role = roleName
  47.     }
  48.     teleportOptions:SetTeleportData(teleportData)
  49.    
  50. end)
  51.  
  52. game:BindToClose(function()
  53.     for i,player in pairs(game.Players:GetPlayers()) do
  54.         local value = player.Role.Value
  55.         SaveRoles:SetAsync(player.UserId, value)
  56.         print("Saved data for "..player.Name)
  57.     end
  58. end)
  59.  
  60. game.Players.PlayerRemoving:Connect(function(player)
  61.     local value = player.Role.Value
  62.  
  63.     if value ~= nil then
  64.         print("Found data to save for "..player.Name.."!")
  65.         SaveRoles:SetAsync(player.UserId, value)
  66.         print("Saved data for "..player.Name)
  67.     else
  68.         print("Did not manage to find data to save for "..player.Name.."!")
  69.     end
  70. end)
  71.  
  72. local CashDataStore = game:GetService("DataStoreService"):GetDataStore("Cash")
  73. local GemsDataStore = game:GetService("DataStoreService"):GetDataStore("Gems")
  74.  
  75. game.Players.PlayerAdded:Connect(function(player)
  76.     local previousData = CashDataStore:GetAsync(player.UserId)
  77.     local previousData2 = GemsDataStore:GetAsync(player.UserId)
  78.    
  79.     local Cash
  80.     local Gems
  81.    
  82.     if previousData ~= nil then
  83.         Cash = previousData
  84.     else
  85.         Cash = 0
  86.         CashDataStore:SetAsync(player.UserId, Cash)
  87.     end
  88.    
  89.     if previousData2 ~= nil then
  90.         Gems = previousData2
  91.     else
  92.         Gems = 0
  93.         GemsDataStore:SetAsync(player.UserId, Gems)
  94.     end
  95.    
  96.     local CashValue = Instance.new("NumberValue", player)
  97.     CashValue.Name = "Cash"
  98.     CashValue.Value = Cash
  99.    
  100.     local gemsValue = Instance.new("NumberValue", player)
  101.     gemsValue.Name = "Gems"
  102.     gemsValue.Value = Gems
  103.    
  104. end)
  105.  
  106. game:BindToClose(function()
  107.     for i,player in pairs(game.Players:GetPlayers()) do
  108.         local value = player.Cash.Value
  109.         local value2 = player.Gems.Value
  110.        
  111.         CashDataStore:SetAsync(player.UserId, value)
  112.         GemsDataStore:SetAsync(player.UserId, value2)
  113.        
  114.         print("Saved data for "..player.Name)
  115.     end
  116. end)
  117.  
  118. game.Players.PlayerRemoving:Connect(function(player)
  119.     local value = player.Cash.Value
  120.     local value2 = player.Gems.Value
  121.    
  122.     if value ~= nil then
  123.         print("Found data to save for "..player.Name.."!")
  124.         CashDataStore:SetAsync(player.UserId, value)
  125.         GemsDataStore:SetAsync(player.UserId, value2)
  126.        
  127.         print("Saved data for "..player.Name)
  128.     else
  129.         print("Did not manage to find data to save for "..player.Name.."!")
  130.     end
  131. end)
  132.  
Advertisement
Add Comment
Please, Sign In to add comment