Geecgo

ee

Oct 2nd, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. local Debug = false -- Set this to true if you want my debug output.
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local Players = game:GetService("Players")
  4.  
  5. local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
  6. local Remotes = ReplicatedStorage:WaitForChild("Remotes", 9e9) -- A second argument in waitforchild what could it mean?
  7. local Balls = workspace:WaitForChild("Balls", 9e9)
  8.  
  9. -- Functions
  10.  
  11. local function print(...) -- Debug print.
  12. if Debug then
  13. warn(...)
  14. end
  15. end
  16.  
  17. local function VerifyBall(Ball) -- Returns nil if the ball isn't a valid projectile; true if it's the right ball.
  18. if typeof(Ball) == "Instance" and Ball:IsA("BasePart") and Ball:IsDescendantOf(Balls) and Ball:GetAttribute("realBall") == true then
  19. return true
  20. end
  21. end
  22.  
  23. local function IsTarget() -- Returns true if we are the current target.
  24. return (Player.Character and Player.Character:FindFirstChild("Highlight"))
  25. end
  26.  
  27. local function Parry() -- Parries.
  28. Remotes:WaitForChild("ParryButtonPress"):Fire()
  29. end
  30.  
  31. -- The actual code
  32.  
  33. Balls.ChildAdded:Connect(function(Ball)
  34. if not VerifyBall(Ball) then
  35. return
  36. end
  37.  
  38. print(`Ball Spawned: {Ball}`)
  39.  
  40. local OldPosition = Ball.Position
  41. local OldTick = tick()
  42.  
  43. Ball:GetPropertyChangedSignal("Position"):Connect(function()
  44. if IsTarget() then -- No need to do the math if we're not being attacked.
  45. local Distance = (Ball.Position - workspace.CurrentCamera.Focus.Position).Magnitude
  46. local Velocity = (OldPosition - Ball.Position).Magnitude -- Fix for .Velocity not working. Yes I got the lowest possible grade in accuplacer math.
  47.  
  48. print(`Distance: {Distance}\nVelocity: {Velocity}\nTime: {Distance / Velocity}`)
  49.  
  50. if (Distance / Velocity) <= 10 then -- Sorry for the magic number. This just works. No, you don't get a slider for this because it's 2am.
  51. Parry()
  52. end
  53. end
  54.  
  55. if (tick() - OldTick >= 1/60) then -- Don't want it to update too quickly because my velocity implementation is aids. Yes, I tried Ball.Velocity. No, it didn't work.
  56. OldTick = tick()
  57. OldPosition = Ball.Position
  58. end
  59. end)
  60. end)
Add Comment
Please, Sign In to add comment