local a=script.Parent local d=require(a:WaitForChild("\067\114\101\097\116\101\077\111\116\111\114\099\121\099\108\101"))local T=require(a:WaitForChild("\065\110\105\109\097\116\101\077\111\116\111\114\099\121\099\108\101"))local j,D local function p()local p=a.Parent if not p then return end local X=p:FindFirstChild("\072\117\109\097\110\111\105\100")local G=p:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if not X or not G or X.Health<0 then return end j=X X.PlatformStand=true D=d()D.Name="\077\111\116\111\114\099\121\099\108\101"D.CFrame=G.CFrame*CFrame.new(0,-1.1,-0.9)D.Parent=p;(D:WaitForChild("\082\117\110\110\105\110\103\083\111\117\110\100")):Play()local B=Instance.new("\087\101\108\100")B.C0=CFrame.new(0,-1.1,-0.9)B.Part0=G B.Part1=D B.Parent=D local g=Instance.new("\066\111\100\121\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121")g.MaxTorque=Vector3.new(0,math.huge,0)g.AngularVelocity=Vector3.new(0,0,0)g.Parent=D local m=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")m.MaxForce=Vector3.new(math.huge,0,math.huge)m.Velocity=Vector3.new(0,0,0)m.P=100 m.Parent=D local H=Instance.new("\066\111\100\121\071\121\114\111")H.MaxTorque=Vector3.new(5000,0,5000)H.P=300 H.D=100 H.Parent=D local V=T(D)while true do V()wait()end end local function X()if j then j.PlatformStand=false end if D then D:Destroy()end end a.Equipped:Connect(p)a.Unequipped:Connect(X)
--[[
TheNexusAvenger

Runs the motorcycle on the server.
--]]

local Tool = script.Parent
local CreateMotorcycle = require(Tool:WaitForChild("CreateMotorcycle"))
local AnimateMotorcycle = require(Tool:WaitForChild("AnimateMotorcycle"))

local CurrentHumanoid,CurrentMotorcycle



--[[
Invoked when the tool is equipped.
--]]
local function OnEquip()
    --Return if the character is invalid.
    local Character = Tool.Parent
    if not Character then return end
    local Humanoid = Character:FindFirstChild("Humanoid")
    local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
    if not Humanoid or not HumanoidRootPart or Humanoid.Health < 0 then return end
    CurrentHumanoid = Humanoid

    --Create the motorcycle.
    Humanoid.PlatformStand = true
    CurrentMotorcycle = CreateMotorcycle()
    CurrentMotorcycle.Name = "Motorcycle"
    CurrentMotorcycle.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,-1.1,-0.9)
    CurrentMotorcycle.Parent = Character
    CurrentMotorcycle:WaitForChild("RunningSound"):Play()

    local TorsoWeld = Instance.new("Weld")
    TorsoWeld.C0 = CFrame.new(0,-1.1,-0.9)
    TorsoWeld.Part0 = HumanoidRootPart
    TorsoWeld.Part1 = CurrentMotorcycle
    TorsoWeld.Parent = CurrentMotorcycle

    local RotationForce = Instance.new("BodyAngularVelocity")
    RotationForce.MaxTorque = Vector3.new(0,math.huge,0)
    RotationForce.AngularVelocity = Vector3.new(0,0,0)
    RotationForce.Parent = CurrentMotorcycle

    local ThrustForce = Instance.new("BodyVelocity")
    ThrustForce.MaxForce = Vector3.new(math.huge,0,math.huge)
    ThrustForce.Velocity = Vector3.new(0,0,0)
    ThrustForce.P = 100
    ThrustForce.Parent = CurrentMotorcycle

    local TurnGyro = Instance.new("BodyGyro")
    TurnGyro.MaxTorque = Vector3.new(5000,0,5000)
    TurnGyro.P = 300
    TurnGyro.D = 100
    TurnGyro.Parent = CurrentMotorcycle

    --Start animating the motorcycle.
    local AnimateMotorcycleStep = AnimateMotorcycle(CurrentMotorcycle)
    while true do
        AnimateMotorcycleStep()
        wait()
    end
end

--[[
Invoked when the tool is unequipped.
--]]
local function OnUnequip()
    --Clear the motorcycle.
    if CurrentHumanoid then
        CurrentHumanoid.PlatformStand = false
    end
    if CurrentMotorcycle then
        CurrentMotorcycle:Destroy()
    end
end



--Connect the events.
Tool.Equipped:Connect(OnEquip)
Tool.Unequipped:Connect(OnUnequip)