Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ball Module
- -- LukeGabrieI
- -- December 15, 2019
- local BallModule = {Client = {}}
- local EQUIP_BALL = "EquipBall"
- local PlayerService = game:GetService("Players")
- --local RepStorage = game:GetService("ReplicatedStorage")
- --local EquipBall = RepStorage:WaitForChild("EquipBall")
- local Tool = script.Parent.Parent.Parent
- _G.Ball = Tool
- local Ball = Tool:WaitForChild("Ball")
- local Attachment = Ball:WaitForChild("Attachment")
- local ToolValues = Tool:WaitForChild("Values")
- local PickUp = ToolValues:WaitForChild("PickUp")
- local BallHandler = ToolValues:WaitForChild("BallHandler")
- local OldHandler = ToolValues:WaitForChild("OldPlayer")
- local Power = ToolValues:WaitForChild("Power")
- local Hand = ToolValues:WaitForChild("Hand")
- local StealDelay = 0
- local StealDistance = 6.25
- spawn(function()
- --Steal Timer
- do
- while wait(0.1) do
- if StealDelay > 0 then
- StealDelay = StealDelay - 0.1
- else
- StealDelay = 0
- PickUp.Value = true
- end
- end
- end
- end)
- local function CheckDistance(object, ballPart)
- return (ballPart.Position - object.Position).magnitude
- end
- local function inWorkspace()
- if Tool.Parent == workspace then
- return true
- else
- return false
- end
- end
- local function NewParent(Player)
- if BallHandler.Value ~= "" then
- if Player.Name ~= BallHandler.Value then
- OldHandler.Value = BallHandler.Value
- return true
- elseif Player.Name == BallHandler.Value then
- OldHandler.Value = ""
- return false
- end
- elseif BallHandler.Value == "" then
- return true
- end
- end
- function BallModule:Start()
- local BallService = self.Services.BallModule
- function _G.RegularEquip(Player, Character, Humanoid)
- --Set Variables
- _G.Ball.Values.Hand.Value = Hand.Value
- _G.Ball.Values.Power.Value = Power.Value
- --Ball Attachment
- local BallAttachment = Ball:FindFirstChild("Attachment")
- if BallAttachment then
- BallAttachment.Part0 = nil
- BallAttachment.Part1 = nil
- BallAttachment:Destroy()
- end
- Tool.Parent = Character
- Humanoid:EquipTool(Tool)
- BallHandler.Value = Player.Name
- local AnimPart = Character:WaitForChild("AnimPart")
- local CloneAttachment = Attachment:Clone()
- CloneAttachment.Parent = Ball
- CloneAttachment.Part0 = AnimPart
- CloneAttachment.Part1 = Ball
- BallService:FireClientEvent(EQUIP_Ball, Player, Power.Value, Hand.Value)
- Ball.CanCollide = false
- wait(1)
- PickUp.Value = true
- end
- end
- function BallModule:AttemptParent(object)
- if object:FindFirstChild("Humanoid") and StealDelay <= 0.1 then
- local Character = object
- local Player = PlayerService:GetPlayerFromCharacter(Character)
- local Humanoid = Character:WaitForChild("Humanoid")
- if Player and Player.Character then
- --Check if Same Player
- if NewParent(Player) then
- StealDelay = 1.7
- else
- StealDelay = 0
- end
- --Equip Ball
- if Humanoid.Health > 0 and Humanoid.PlatformStand == false then
- --Reset Travel
- PickUp.Value = false
- --Equip Function
- _G.RegularEquip(Player, Character, Humanoid)
- end
- end
- end
- end
- function BallModule:AttemptRegistry(object)
- --Not Current Parent
- if not PlayerService:FindFirstChild(BallHandler.Value) then
- return true
- --Character w/ Ball or Workspace
- elseif CheckDistance(object, Ball) <= StealDistance or inWorkspace() then
- return true
- else
- return false
- end
- end
- function BallModule:Init()
- self:RegisterClientEvent(EQUIP_BALL)
- end
- return BallModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement