SHARE
TWEET

ballmodule

a guest Dec 15th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Ball Module
  2. -- LukeGabrieI
  3. -- December 15, 2019
  4.  
  5.  
  6.  
  7. local BallModule = {Client = {}}
  8.  
  9. local EQUIP_BALL = "EquipBall"
  10.  
  11. local PlayerService = game:GetService("Players")
  12. --local RepStorage = game:GetService("ReplicatedStorage")
  13. --local EquipBall = RepStorage:WaitForChild("EquipBall")
  14. local Tool = script.Parent.Parent.Parent
  15. _G.Ball = Tool
  16. local Ball = Tool:WaitForChild("Ball")
  17. local Attachment = Ball:WaitForChild("Attachment")
  18.  
  19. local ToolValues = Tool:WaitForChild("Values")
  20. local PickUp = ToolValues:WaitForChild("PickUp")
  21. local BallHandler = ToolValues:WaitForChild("BallHandler")
  22. local OldHandler = ToolValues:WaitForChild("OldPlayer")
  23. local Power = ToolValues:WaitForChild("Power")
  24. local Hand = ToolValues:WaitForChild("Hand")
  25.  
  26. local StealDelay = 0
  27. local StealDistance = 6.25
  28.  
  29. spawn(function()
  30.     --Steal Timer
  31.     do
  32.         while wait(0.1) do
  33.             if StealDelay > 0 then
  34.                 StealDelay = StealDelay - 0.1
  35.             else
  36.                 StealDelay = 0
  37.                 PickUp.Value = true
  38.             end
  39.         end
  40.     end
  41. end)
  42.  
  43. local function CheckDistance(object, ballPart)
  44.     return (ballPart.Position - object.Position).magnitude
  45. end
  46.  
  47. local function inWorkspace()
  48.     if Tool.Parent == workspace then
  49.         return true
  50.     else
  51.         return false
  52.     end
  53. end
  54.  
  55. local function NewParent(Player)
  56.     if BallHandler.Value ~= "" then
  57.         if Player.Name ~= BallHandler.Value then
  58.            
  59.             OldHandler.Value = BallHandler.Value
  60.            
  61.             return true
  62.            
  63.         elseif Player.Name == BallHandler.Value then
  64.            
  65.             OldHandler.Value = ""
  66.            
  67.             return false
  68.         end
  69.     elseif BallHandler.Value == "" then
  70.         return true
  71.     end
  72. end
  73.  
  74. function BallModule:Start()
  75.  
  76.     local BallService = self.Services.BallModule
  77.  
  78.     function _G.RegularEquip(Player, Character, Humanoid)
  79.        
  80.         --Set Variables
  81.         _G.Ball.Values.Hand.Value = Hand.Value
  82.         _G.Ball.Values.Power.Value = Power.Value
  83.         --Ball Attachment
  84.         local BallAttachment = Ball:FindFirstChild("Attachment")
  85.         if BallAttachment then
  86.             BallAttachment.Part0 = nil
  87.             BallAttachment.Part1 = nil
  88.             BallAttachment:Destroy()
  89.         end
  90.         Tool.Parent = Character
  91.         Humanoid:EquipTool(Tool)
  92.         BallHandler.Value = Player.Name
  93.         local AnimPart = Character:WaitForChild("AnimPart")
  94.         local CloneAttachment = Attachment:Clone()
  95.         CloneAttachment.Parent = Ball
  96.         CloneAttachment.Part0 = AnimPart
  97.         CloneAttachment.Part1 = Ball
  98.         BallService:FireClientEvent(EQUIP_Ball, Player, Power.Value, Hand.Value)
  99.         Ball.CanCollide = false
  100.         wait(1)
  101.         PickUp.Value = true
  102.        
  103.     end
  104.    
  105. end
  106.  
  107. function BallModule:AttemptParent(object)
  108.    
  109.     if object:FindFirstChild("Humanoid") and StealDelay <= 0.1 then
  110.         local Character = object
  111.         local Player = PlayerService:GetPlayerFromCharacter(Character)
  112.         local Humanoid = Character:WaitForChild("Humanoid")
  113.        
  114.         if Player and Player.Character then
  115.  
  116.             --Check if Same Player
  117.             if NewParent(Player) then
  118.                 StealDelay = 1.7
  119.             else
  120.                 StealDelay = 0
  121.             end
  122.            
  123.             --Equip Ball
  124.             if Humanoid.Health > 0 and Humanoid.PlatformStand == false then
  125.                
  126.                 --Reset Travel
  127.                 PickUp.Value = false
  128.                
  129.                 --Equip Function
  130.                 _G.RegularEquip(Player, Character, Humanoid)
  131.                    
  132.             end
  133.            
  134.         end
  135.        
  136.     end
  137. end
  138.  
  139. function BallModule:AttemptRegistry(object)
  140.     --Not Current Parent
  141.     if not PlayerService:FindFirstChild(BallHandler.Value) then
  142.         return true
  143.     --Character w/ Ball or Workspace
  144.     elseif CheckDistance(object, Ball) <= StealDistance or inWorkspace() then
  145.         return true
  146.     else
  147.         return false
  148.     end
  149. end
  150.  
  151.  
  152. function BallModule:Init()
  153.     self:RegisterClientEvent(EQUIP_BALL)
  154. end
  155.  
  156.  
  157. return BallModule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top