DevKxnq1221

Untitled

Sep 8th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.15 KB | None | 0 0
  1. --[[
  2.    
  3.  ____                              __              
  4. /\  _`\                           /\ \            
  5. \ \,\L\_\  _____      __     __   \_\ \  __  __    
  6.  \/_\__ \ /\ '__`\  /'__`\ /'__`\ /'_` \/\ \/\ \  
  7.    /\ \L\ \ \ \L\ \/\  __//\  __//\ \L\ \ \ \_\ \  
  8.    \ `\____\ \ ,__/\ \____\ \____\ \___,_\/`____ \
  9.     \/_____/\ \ \/  \/____/\/____/\/__,_ /`/___/> \
  10.              \ \_\                           /\___/
  11.               \/_/                           \/__/
  12.  
  13.         --  Speedy Systems  --
  14. --]]
  15.  
  16. local DataStoreService = game:GetService("DataStoreService")
  17. local myDataStore = DataStoreService:GetDataStore("myDataStore")
  18.  
  19. game.Players.PlayerAdded:Connect(function(plr)
  20.     local leaderstats = Instance.new("Folder")
  21.     leaderstats.Name = "leaderstats"
  22.     leaderstats.Parent = plr
  23.  
  24.     local otherData = Instance.new("Folder")
  25.     otherData.Name = "otherData"
  26.     otherData.Parent = plr
  27.    
  28.     local Coins = Instance.new("IntValue")
  29.     local Logs = Instance.new("IntValue")
  30.     local TreesCut = Instance.new("IntValue")
  31.     local LogSpace = Instance.new("IntValue")
  32.     local currentDoors = Instance.new("Folder")
  33.    
  34. --// Add comas
  35.     function addComas(str)
  36.     return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
  37. end
  38.  
  39.     Coins.Changed:Connect(function()
  40.         plr.PlayerGui:WaitForChild("MainGui").Stats.Coins.Icon.Amount.Text = addComas(tostring(Coins.Value))
  41.     end)
  42.  
  43.     Logs.Changed:Connect(function()
  44.         if Logs.Value <= LogSpace.Value then
  45.             plr.PlayerGui:WaitForChild("MainGui").Stats.Logs.AmountV.Value = addComas(tostring(Logs.Value))
  46.         else
  47.             Logs.Value = addComas(tostring(Logs.Value))
  48.         end
  49.     end)
  50.    
  51.     Coins.Name = "💰Coins"
  52.     Logs.Name = "🌲Logs"
  53.     TreesCut.Name = "🌳Trees Cut"
  54.     LogSpace.Name = "LogSpace"
  55.     currentDoors.Name = "currentDoors"
  56.    
  57.     Coins.Parent = leaderstats
  58.     LogSpace.Parent = otherData
  59.     Logs.Parent = leaderstats
  60.     TreesCut.Parent = leaderstats
  61.     currentDoors.Parent = plr
  62.    
  63.     local data1
  64.     local data2
  65.     local data3
  66.     local data4
  67.     local data5
  68.    
  69.     local success, errormessage = pcall(function()
  70.         data1 = myDataStore:GetAsync(plr.UserId.."-Coins")
  71.         data2 = myDataStore:GetAsync(plr.UserId.."-Logs")
  72.         data3 = myDataStore:GetAsync(plr.UserId.."-TreesCut")
  73.         data4 = myDataStore:GetAsync(plr.UserId.."-LogSpace")
  74.         data5 = myDataStore:GetAsync(plr.UserId.."-currentDoors")
  75.     end)
  76.    
  77.     if data1 and data2 and data3 and data4 and data5 then
  78.         Coins.Value = data1
  79.         TreesCut.Value = data3
  80.         LogSpace.Value = data4
  81.         Logs.Value = data2
  82.         Logs.Value = Logs.Value + 1
  83.         Logs.Value = Logs.Value - 1
  84.         currentDoors = data5
  85.         else
  86.         print("An error occurred while getting player's data!")
  87.         warn(errormessage)
  88.     end
  89.  
  90.     if LogSpace.Value == 0 then
  91.         LogSpace.Value = 10
  92.     end
  93.    
  94.     local ii = 1
  95.     local u = workspace.Earth.Biomes.BiomeDoors[myDataStore:GetAsync(plr.UserId.."-currentDoors")]:WaitForChild("Num").Value
  96.    
  97.     for i, v in pairs (workspace.Earth.Biomes.BiomeDoors:GetChildren()) do
  98.         if ii <= u then
  99.             if v.Num.Value == ii  and v.Num.Value ~= u then
  100.                 if v.Num.Value == nil then print("nil") end
  101.                 game.ReplicatedStorage.Remotes.areaHandler:FireClient(plr, v.Name)
  102.                 ii = ii + 1
  103.             elseif v.Num.Value == u and v.Num.Value == ii then
  104.                 game.ReplicatedStorage.Remotes.areaHandler:FireClient(plr, v.Name)
  105.                 ii = ii + 1
  106.             end
  107.         end
  108.     end
  109.    
  110. end)
  111.  
  112. game.Players.PlayerRemoving:Connect(function(plr)
  113.    
  114.     local success, errormessage = pcall(function()
  115.         myDataStore:SetAsync(plr.UserId.."-Coins", plr.leaderstats["💰Coins"].Value)
  116.         myDataStore:SetAsync(plr.UserId.."-Logs", plr.leaderstats["🌲Logs"].Value)
  117.         myDataStore:SetAsync(plr.UserId.."-TreesCut", plr.leaderstats["🌳Trees Cut"].Value)
  118.         myDataStore:SetAsync(plr.UserId.."-LogSpace", plr.otherData.LogSpace.Value)
  119.         myDataStore:SetAsync(plr.UserId.."-currentDoors", plr.currentDoors.Value)
  120.     end)
  121.    
  122.     if success then
  123.         print("Data was successfully saved!")
  124.     else
  125.         print("An error occurred!")
  126.         warn(errormessage)
  127.     end
  128. end)
Advertisement
Add Comment
Please, Sign In to add comment