Advertisement
HowToRoblox

JumpHandler

Feb 4th, 2023
2,977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. local startingJump = 0
  2.  
  3. local increment = 1
  4. local period = 1
  5.  
  6. function calculateJumpIncrease(wins)
  7.    
  8.     local increase = increment + wins
  9.     return increase
  10. end
  11.  
  12.  
  13. local dss = game:GetService("DataStoreService")
  14. local datastore = dss:GetDataStore("DATA STORE")
  15.  
  16.  
  17. function saveData(plr)
  18.     if not plr:FindFirstChild("DATA FAILED TO LOAD") then
  19.  
  20.         local jump = plr.leaderstats.Jump.Value
  21.         local wins = plr.leaderstats.Wins.Value
  22.        
  23.         local compiledData = {jump, wins}
  24.  
  25.         local success, err = nil, nil
  26.         while not success do
  27.             success, err = pcall(function()
  28.                 datastore:SetAsync(plr.UserId, compiledData)
  29.             end)
  30.             if err then
  31.                 warn(err)
  32.             end
  33.             task.wait(0.02)
  34.         end
  35.     end
  36. end
  37.  
  38. game.Players.PlayerRemoving:Connect(saveData)
  39. game:BindToClose(function()
  40.     for _, plr in pairs(game.Players:GetPlayers()) do
  41.         saveData(plr)
  42.     end
  43. end)
  44.  
  45. game.Players.PlayerAdded:Connect(function(plr)
  46.  
  47.     local dataFailedWarning = Instance.new("StringValue")
  48.     dataFailedWarning.Name = "DATA FAILED TO LOAD"
  49.     dataFailedWarning.Parent = plr
  50.  
  51.     local success, plrData = nil, nil
  52.     while not success do
  53.         success, plrData = pcall(function()
  54.             return datastore:GetAsync(plr.UserId)
  55.         end)
  56.         task.wait(0.02)
  57.     end
  58.     dataFailedWarning:Destroy()
  59.  
  60.     if not plrData then
  61.         plrData = {startingJump, 0}
  62.     end
  63.  
  64.     local ls = Instance.new("Folder")
  65.     ls.Name = "leaderstats"
  66.  
  67.     local jumpVal = Instance.new("IntValue")
  68.     jumpVal.Name = "Jump"
  69.     jumpVal.Value = plrData[1]
  70.     jumpVal.Parent = ls
  71.  
  72.     local winsVal = Instance.new("IntValue")
  73.     winsVal.Name = "Wins"
  74.     winsVal.Value = plrData[2]
  75.     winsVal.Parent = ls
  76.  
  77.     ls.Parent = plr
  78.    
  79.     local char = plr.Character or plr.CharacterAdded:Wait()
  80.     char:WaitForChild("Humanoid").JumpHeight = jumpVal.Value
  81.    
  82.     plr.CharacterAdded:Connect(function(char)
  83.         char:WaitForChild("Humanoid").JumpHeight = jumpVal.Value
  84.     end)
  85. end)
  86.  
  87.  
  88. function handleWinPad(winpad)
  89.    
  90.     local onDebounce = {}
  91.     local debounceTime = 5
  92.    
  93.     winpad.Touched:Connect(function(hit)
  94.        
  95.         local plr = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  96.        
  97.         if plr and not onDebounce[plr] then
  98.             onDebounce[plr] = true
  99.            
  100.             plr:LoadCharacter()
  101.            
  102.             plr.leaderstats.Jump.Value = startingJump
  103.             plr.leaderstats.Wins.Value += tonumber(winpad.Name) or 1
  104.            
  105.             task.wait(debounceTime)
  106.             onDebounce[plr] = nil
  107.         end
  108.     end)
  109. end
  110.  
  111. for _, winpad in pairs(workspace:WaitForChild("WinPads"):GetChildren()) do
  112.     handleWinPad(winpad)
  113. end
  114.  
  115. workspace.WinPads.ChildAdded:Connect(handleWinPad)
  116.  
  117.  
  118. while true do
  119.    
  120.     task.wait(period)
  121.    
  122.     for _, plr in pairs(game.Players:GetPlayers()) do
  123.        
  124.         local plrLS = plr:FindFirstChild("leaderstats")
  125.         if plrLS then
  126.             local plrJump = plrLS:FindFirstChild("Jump")
  127.             local plrWins = plrLS:FindFirstChild("Wins")
  128.            
  129.             if plrJump and plrWins then
  130.                 local increase = calculateJumpIncrease(plrWins.Value)
  131.                 plrJump.Value += increase
  132.                
  133.                 if plr.Character and plr.Character:FindFirstChild("Humanoid") then
  134.                     plr.Character.Humanoid.JumpHeight = plrJump.Value
  135.                 end
  136.             end
  137.         end
  138.     end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement