Advertisement
Sungmingamerpro13

My SaveRoles Leaderstats Main Game

Sep 3rd, 2024
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.39 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.     if player:WaitForChild("Role").Value >= "Default" then
  11.         player:WaitForChild("Role").Value = "Default"
  12.     elseif player:WaitForChild("Role").Value == "Athlete" then
  13.         player:WaitForChild("Role").Value = "Athlete"
  14.     elseif player:WaitForChild("Role").Value == "Super Protector" then
  15.         player:WaitForChild("Role").Value = "Super Protector"
  16.     elseif player:WaitForChild("Role").Value == "Delivery" then
  17.         player:WaitForChild("Role").Value = "Delivery"
  18.         game.ServerStorage.SavedTools:WaitForChild("PizzaBox"):Clone().Parent = player.Backpack
  19.     end
  20.    
  21. end)
  22.  
  23. game:BindToClose(function()
  24.     for i,player in pairs(game.Players:GetPlayers()) do
  25.         local value = player.Role.Value
  26.         SaveRoles:SetAsync(player.UserId, value)
  27.         print("Saved data for "..player.Name)
  28.     end
  29. end)
  30.  
  31. game.Players.PlayerRemoving:Connect(function(player)
  32.     local value = player.Role.Value
  33.  
  34.     if value ~= nil then
  35.         print("Found data to save for "..player.Name.."!")
  36.         SaveRoles:SetAsync(player.UserId, value)
  37.         print("Saved data for "..player.Name)
  38.     else
  39.         print("Did not manage to find data to save for "..player.Name.."!")
  40.     end
  41. end)
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement