20CrackScratch08

Best Times Automatic Leaderboard

Apr 10th, 2022 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.48 KB | None | 0 0
  1. local DSS = game:GetService("DataStoreService")
  2. local LB = DSS:GetDataStore("Leaderboards")
  3.  
  4. game.ReplicatedStorage.RemoteEvents.Update.OnServerEvent:Connect(function(plr, Time, obby) -- Se detecta
  5.     print("Detected!")
  6.     print(Time)
  7.     Time *= 10
  8.     Time = math.floor(Time)
  9.     Time = Time / 10
  10.    
  11.     print(Time)
  12.    
  13.     if(Time > 2) then
  14.         print(obby)
  15.         print(Time)
  16.         if(obby == "OTO" and Time < 15) then else if(obby == "ETO" and Time < 9.5) then else if(obby == "EKO" and Time < 10.2) then else if(obby == "EWHO" and Time < 12) then else if(obby == "MTO" and Time < 14) then else if(obby == "MKO" and Time < 14.2) then else if(obby == "MWHO" and Time < 19) then else if(obby == "HTO" and Time < 14.5) then else if(obby == "HKO" and Time <16.5) then else if(obby == "HWHO" and Time < 18) then else
  17.                                                 if(game.ReplicatedStorage.Leaderboards[obby].Times.P5.Value >= Time or game.ReplicatedStorage.Leaderboards[obby].Times.P5.Value == 0) then -- Si es un record...
  18.                                                     local currentPos = 5
  19.                                                     local score = 0
  20.                                                     print(obby)
  21.                                                     for i,v in pairs(game.ReplicatedStorage.Leaderboards[obby].Times:GetChildren()) do -- Por cada posicion...
  22.                                                         print("Checking with "..i.." in "..obby)
  23.                                                         if v.Value >= Time then -- Si el valor de la posicion es mayor que el tiempo...
  24.                                                             if score == 0 then -- Si no se ha encontrado el record se actualiza
  25.                                                                 print("Setting position as "..i)
  26.                                                                 score = i
  27.                                                             end
  28.                                                         end
  29.                                                     end
  30.                                                     local otherScore = -1
  31.                                                     for i,v in pairs(game.ReplicatedStorage.Leaderboards[obby].Persons:GetChildren()) do -- Por cada posicion...
  32.                                                         if v.Value == plr.Name then
  33.                                                             otherScore = i
  34.                                                         end
  35.                                                     end
  36.                                                     local items = {
  37.                                                         Time1 = LB:GetAsync(obby)["Time1"],
  38.                                                         Time2 = LB:GetAsync(obby)["Time2"],
  39.                                                         Time3 = LB:GetAsync(obby)["Time3"],
  40.                                                         Time4 = LB:GetAsync(obby)["Time4"],
  41.                                                         Time5 = LB:GetAsync(obby)["Time5"],
  42.  
  43.                                                         Person1 = LB:GetAsync(obby)["Person1"],
  44.                                                         Person2 = LB:GetAsync(obby)["Person2"],
  45.                                                         Person3 = LB:GetAsync(obby)["Person3"],
  46.                                                         Person4 = LB:GetAsync(obby)["Person4"],
  47.                                                         Person5 = LB:GetAsync(obby)["Person5"]
  48.                                                     }
  49.  
  50.                                                     print(otherScore)
  51.  
  52.                                                     if otherScore >= 1 then
  53.                                                         print("Has alr a score!")
  54.                                                         print(otherScore)
  55.                                                         print(score)
  56.                                                         if otherScore > score then
  57.                                                             print("Got better time!")
  58.                                                             local pos = otherScore
  59.                                                             while pos <= 5 do
  60.                                                                 print("Chaning "..(pos + 1).." to new position "..pos)
  61.  
  62.                                                                 if pos < 5 then
  63.                                                                     game.ReplicatedStorage.Leaderboards[obby].Times["P"..pos].Value = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(pos + 1)].Value or 0-- Se actualizan los valores
  64.                                                                     items["Time"..pos] = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(pos + 1)].value or 0
  65.  
  66.                                                                     game.ReplicatedStorage.Leaderboards[obby].Persons["P"..pos].Value = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(pos + 1)].Value or "None"-- Se actualizan los valores
  67.                                                                     items["Person"..pos] = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(pos + 1)].value or "None"
  68.                                                                 else   
  69.                                                                     game.ReplicatedStorage.Leaderboards[obby].Times["P"..pos].Value = 0-- Se actualizan los valores
  70.                                                                     items["Time"..pos] = 0
  71.  
  72.                                                                     game.ReplicatedStorage.Leaderboards[obby].Persons["P"..pos].Value = "None"-- Se actualizan los valores
  73.                                                                     items["Person"..pos] = "None"
  74.                                                                 end
  75.  
  76.                                                                 pos = pos + 1
  77.                                                             end
  78.                                                             local newPos = 5
  79.                                                             while newPos > score do -- Loop desde el ultimo hasta la nueva posicion
  80.                                                                 print("Changing "..newPos)
  81.                                                                 game.ReplicatedStorage.Leaderboards[obby].Times["P"..newPos].Value = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(newPos - 1)].Value -- Se actualizan los valores
  82.                                                                 items["Time"..newPos] = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(newPos - 1)].value
  83.                                                                 game.ReplicatedStorage.Leaderboards[obby].Persons["P"..newPos].Value = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(newPos - 1)].Value -- Se actualizan los valores
  84.                                                                 items["Person"..newPos] = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(newPos - 1)].value
  85.                                                                 newPos = newPos - 1
  86.                                                             end
  87.                                                             game.ReplicatedStorage.Leaderboards[obby].Times["P"..score].Value = Time
  88.                                                             items["Time"..score] = Time
  89.                                                             game.ReplicatedStorage.Leaderboards[obby].Persons["P"..score].Value = plr.Name
  90.                                                             items["Person"..score] = plr.Name              
  91.                                                         end
  92.                                                         if otherScore == score then
  93.                                                             print("Same position :0")
  94.                                                             game.ReplicatedStorage.Leaderboards[obby].Times["P"..score].Value = Time
  95.                                                             items["Time"..score] = Time
  96.                                                         end
  97.                                                     end
  98.                                                     if otherScore == -1 then
  99.                                                         while currentPos > score do -- Loop desde el ultimo hasta la nueva posicion
  100.                                                             print("Changing "..currentPos)
  101.                                                             game.ReplicatedStorage.Leaderboards[obby].Times["P"..currentPos].Value = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(currentPos - 1)].Value -- Se actualizan los valores
  102.                                                             items["Time"..currentPos] = game.ReplicatedStorage.Leaderboards[obby].Times["P"..(currentPos - 1)].value
  103.                                                             game.ReplicatedStorage.Leaderboards[obby].Persons["P"..currentPos].Value = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(currentPos - 1)].Value -- Se actualizan los valores
  104.                                                             items["Person"..currentPos] = game.ReplicatedStorage.Leaderboards[obby].Persons["P"..(currentPos - 1)].value
  105.                                                             currentPos = currentPos - 1
  106.                                                         end
  107.                                                         game.ReplicatedStorage.Leaderboards[obby].Times["P"..score].Value = Time
  108.                                                         items["Time"..score] = Time
  109.                                                         game.ReplicatedStorage.Leaderboards[obby].Persons["P"..score].Value = plr.Name
  110.                                                         items["Person"..score] = plr.Name
  111.                                                     end
  112.  
  113.                                                     LB:SetAsync(obby, items)
  114.                                                 end
  115.                                             end
  116.                                         end
  117.                                     end
  118.                                 end
  119.                             end
  120.                         end
  121.                     end
  122.                 end
  123.             end
  124.         end
  125.     end
  126. end)
Add Comment
Please, Sign In to add comment