DE_Speedruns

Untitled

Nov 19th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. local function startAutoParry()
  2. local player = game.Players.LocalPlayer
  3. local character = player.Character or player.CharacterAdded:Wait()
  4. local replicatedStorage = game:GetService("ReplicatedStorage")
  5. local runService = game:GetService("RunService")
  6. local parryButtonPress = replicatedStorage.Remotes.ParryButtonPress
  7. local ballsFolder = workspace:WaitForChild("Balls")
  8.  
  9. local players = game:GetService("Players")
  10. local localPlayer = players.LocalPlayer
  11.  
  12. local function printMessage()
  13. print("Auto Parry Enabled")
  14. end
  15. printMessage()
  16.  
  17. local function onCharacterAdded(newCharacter)
  18. character = newCharacter
  19. end
  20.  
  21. player.CharacterAdded:Connect(onCharacterAdded)
  22.  
  23. local focusedBall = nil
  24.  
  25. local function chooseNewFocusedBall()
  26. local balls = ballsFolder:GetChildren()
  27. focusedBall = nil
  28. for _, ball in ipairs(balls) do
  29. if ball:GetAttribute("realBall") == true then
  30. focusedBall = ball
  31. break
  32. end
  33. end
  34. end
  35.  
  36. chooseNewFocusedBall()
  37.  
  38. local function timeUntilImpact(ballVelocity, distanceToPlayer, playerVelocity)
  39. local directionToPlayer = (character.HumanoidRootPart.Position - focusedBall.Position).Unit
  40. local velocityTowardsPlayer = ballVelocity:Dot(directionToPlayer) - playerVelocity:Dot(directionToPlayer)
  41.  
  42. if velocityTowardsPlayer <= 100 then
  43. return math.huge
  44. end
  45.  
  46. local distanceToBeCovered = distanceToPlayer - 50
  47. return distanceToBeCovered / velocityTowardsPlayer
  48. end
  49.  
  50. local BASE_THRESHOLD = 0.15
  51. local VELOCITY_SCALING_FACTOR = 0
  52.  
  53. local function getDynamicThreshold(ballVelocityMagnitude)
  54. local adjustedThreshold = BASE_THRESHOLD - (ballVelocityMagnitude * VELOCITY_SCALING_FACTOR)
  55. return math.max(0.17, adjustedThreshold)
  56. end
  57.  
  58. local function checkBallDistance()
  59. if not character:FindFirstChild("Highlight") then return end
  60. local charPos = character.PrimaryPart.Position
  61. local charVel = character.PrimaryPart.Velocity
  62.  
  63. if focusedBall and not focusedBall.Parent then
  64. chooseNewFocusedBall()
  65. end
  66.  
  67. if not focusedBall then return end
  68.  
  69. local ball = focusedBall
  70. local distanceToPlayer = (ball.Position - charPos).Magnitude
  71.  
  72. if distanceToPlayer < 26 then
  73. game.ReplicatedStorage.Remotes.ParryButtonPress:Fire()
  74. return
  75. end
  76.  
  77. local timeToImpact = timeUntilImpact(ball.Velocity, distanceToPlayer, charVel)
  78. local dynamicThreshold = getDynamicThreshold(ball.Velocity.Magnitude)
  79.  
  80. if timeToImpact < dynamicThreshold then
  81. parryButtonPress:Fire()
  82. end
  83. end
  84.  
  85. heartbeatConnection = game:GetService("RunService").Heartbeat:Connect(function()
  86. checkBallDistance()
  87. end)
  88. end
  89.  
  90. local function stopAutoParry()
  91. if heartbeatConnection then
  92. heartbeatConnection:Disconnect()
  93. heartbeatConnection = nil
  94. end
  95. end
  96. startAutoParry()
Add Comment
Please, Sign In to add comment