Advertisement
Sungmingamerpro13

My Horror Friends Leaderstats Main Game

Jan 30th, 2023 (edited)
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.08 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveCurrency = game:GetService("DataStoreService"):GetDataStore("Wins")
  3. local SaveCurrency2 = game:GetService("DataStoreService"):GetDataStore("Rounds")
  4. local SaveCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SaveExtraLives = game:GetService("DataStoreService"):GetDataStore("Lives")
  6.  
  7. local VIPGamepassId = 94862586
  8. game.Players.PlayerAdded:Connect(function(player)
  9.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  10.         local Folder = Instance.new("Folder",player)
  11.         Folder.Name = "leaderstats"
  12.  
  13.         local Currency = Instance.new("NumberValue",Folder)
  14.         Currency.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  15.         Currency.Value = SaveCurrency:GetAsync(player.UserId) or 0
  16.  
  17.         local Currency2 = Instance.new("NumberValue",Folder)
  18.         Currency2.Name = game.ReplicatedStorage.Tags.RoundsValue.Value
  19.         Currency2.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  20.  
  21.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  22.         local Coins
  23.  
  24.         if previousData ~= nil then
  25.             Coins = previousData
  26.         else
  27.             Coins = 0
  28.             SaveCurrency3:SetAsync(player.UserId, 0)
  29.         end
  30.  
  31.         local CoinsValue = Instance.new("NumberValue", player)
  32.         CoinsValue.Name = "Coins"
  33.         CoinsValue.Value = Coins
  34.  
  35.         local previousData2 = SaveExtraLives:GetAsync(player.UserId)
  36.         local Lives
  37.  
  38.         if previousData2 ~= nil then
  39.             Lives = previousData2
  40.         else
  41.             Lives = 0
  42.             SaveExtraLives:SetAsync(player.UserId, 0)
  43.         end
  44.  
  45.         local ExtraLivesValue = Instance.new("NumberValue", player)
  46.         ExtraLivesValue.Name = "Lives"
  47.         ExtraLivesValue.Value = Lives
  48.  
  49.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  50.             player.Coins.Value = player.Coins.Value * 2
  51.         end
  52.     end
  53. end)
  54.  
  55. game.Players.PlayerRemoving:Connect(function(player)
  56.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  57.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  58.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  59.     end
  60. end)
  61.  
  62. game:BindToClose(function()
  63.     print("STOPPED!")
  64.  
  65.     for i,player in pairs(game.Players:GetPlayers()) do
  66.         local value = player.Coins.Value
  67.         SaveCurrency3:SetAsync(player.UserId, value)
  68.         print("Saved data for "..player.Name)
  69.     end
  70. end)
  71.  
  72. game.Players.PlayerRemoving:Connect(function(player)
  73.     local value = player.Coins.Value
  74.  
  75.     if value ~= nil then
  76.         print("Found data to save for "..player.Name.."!")
  77.         SaveCurrency3:SetAsync(player.UserId, value)
  78.         print("Saved data for "..player.Name)
  79.     else
  80.         print("Did not manage to find data to save for "..player.Name.."!")
  81.     end
  82. end)
  83.  
  84. game:BindToClose(function()
  85.     print("STOPPED!")
  86.  
  87.     for i, player in pairs(game.Players:GetPlayers()) do
  88.         local value2 = player.Lives.Value
  89.         SaveExtraLives:SetAsync(player.UserId, value2)
  90.     end
  91. end)
  92.  
  93. game.Players.PlayerRemoving:Connect(function(player)
  94.     local value2 = player.Lives.Value
  95.  
  96.     if value2 ~= nil then
  97.         print("Found data to save for "..player.Name.."!")
  98.         SaveExtraLives:SetAsync(player.UserId, value2)
  99.         print("Saved data for "..player.Name)
  100.     else
  101.         print("Did not manage to find data to save for "..player.Name.."!")
  102.     end
  103. end)
  104.  
  105. game.Players.PlayerAdded:connect(function(player)
  106.     player.CharacterAdded:connect(function(char)
  107.  
  108.         char.Humanoid.Died:connect(function()
  109.             SaveCurrency2:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  110.             SaveExtraLives:SetAsync(player.UserId, player.Lives.Value)
  111.             player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  112.             player.Lives.Value = player.Lives.Value - 1
  113.         end)
  114.     end)
  115. end)
  116.  
  117.  
  118.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement