dhruvil123

ball tp

Oct 26th, 2020 (edited)
934
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local LocalPlayer = game:GetService("Players").LocalPlayer
  2.  
  3.  
  4.  
  5. local TPWithinStuds = true       -- if the ball has to be within X studs (next line)
  6. local StudsToTpWithin = 9        -- basically if tpwithingstuds is true the studs the ball will tp within
  7. local TpTo = 3                   -- 1 = left leg, 2 = right leg, 3 = humanoidrootpart
  8. local Y_Offset = 2
  9.  
  10. local Key = "J"
  11.  
  12. local BallName = "TPS" -- just in case a game has a different name for ball, usually it's TPS or Ball
  13.  
  14. local TpPart = nil
  15. local function SetUpTpPart()
  16. if TpTo == 1 and LocalPlayer.Character:FindFirstChild("Left Leg") then
  17.     TpPart = LocalPlayer.Character:FindFirstChild("Left Leg")
  18. elseif TpTo == 2 and LocalPlayer.Character:FindFirstChild("Right Leg") then
  19.     TpPart = LocalPlayer.Character:FindFirstChild("Right Leg")
  20. elseif TpTo == 3 and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
  21.     TpPart = LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
  22. else
  23.     --return warn("Error: TpTo variable must be either 1, 2, or 3")
  24. end
  25. end
  26.  
  27. SetUpTpPart()
  28.  
  29. LocalPlayer.CharacterAdded:Connect(SetUpTpPart())
  30.  
  31. if TpTo == 3 then
  32.     Y_Offset = Y_Offset + 2
  33. end
  34.  
  35. local ClosestBall = nil
  36. local CurrentClosestBallPos = math.huge
  37.  
  38. LocalPlayer:GetMouse().KeyDown:Connect(function(k)
  39.     if string.lower(k) == string.lower(Key) then
  40.         local noerror, caughterror = pcall(function()
  41.         ClosestBall = nil
  42.         CurrentClosestBallPos = math.huge
  43.  
  44.         for i, v in pairs(workspace:GetDescendants()) do
  45.             if v.ClassName == "Part" and v.Parent.ClassName ~= "Attachment" and v.Parent.ClassName ~= "Weld" and (v.Shape == "Ball" or v:FindFirstChildOfClass("BodyForce")) and LocalPlayer.Character and not TpPart == nil then
  46.                 if (TpPart.Position - v.Position).Magnitude < CurrentClosestBallPos then
  47.                     CurrentClosestBallPos = (TpPart.Position - v.Position).Magnitude
  48.                     ClosestBall = v
  49.                 end
  50.             end
  51.         end
  52.  
  53.        
  54.         if ClosestBall ~= nil and LocalPlayer.Character and not TpPart == nil then
  55.             if TPWithinStuds == true then
  56.                 if (ClosestBall.Position - (TpPart.Position + Vector3.new(0, Y_Offset, 0))).Magnitude <= StudsToTpWithin then
  57.                     ClosestBall.CFrame = TpPart.CFrame + TpPart.CFrame.UpVector * (-0.5 + Y_Offset) + TpPart.CFrame.LookVector * 1
  58.                 end
  59.             else
  60.                 ClosestBall.CFrame = TpPart.CFrame + TpPart.CFrame.UpVector * (-0.5 + Y_Offset) + TpPart.CFrame.LookVector * 1
  61.             end
  62.         end
  63.         end)
  64.         if not noerror then
  65.             --error(“Error found:“, caughterror)
  66.         end
  67.     end
  68. end)
RAW Paste Data