Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local api = {}
- local metatable = {__index = api}
- local tws = game["TweenService"]
- local runservice = game["Run Service"]
- function api.CreateModel(player)
- local self = {}
- setmetatable(self, metatable)
- self.Character = player.Character
- self.RightGear = self.Character.RightGear
- self.LeftGear = self.Character.LeftGear
- self.Hooks = Instance.new('Folder', self.Character)
- self.Hooks.Name = 'Hooks'
- self.BodyVelocity = Instance.new('BodyVelocity', self.Character)
- self.BodyGyro = Instance.new('BodyGyro', self.Character)
- self.BodyGyro.P = 1e+5
- self.BodyGyro.MaxTorque = Vector3.new(1e+3, 1e+3, 1e+3)
- self.Variables = {}
- self.Variables.RightActive = false
- self.Variables.LeftActive = false
- self.Variables.TurningRight = false
- self.Variables.TurningLeft = false
- self.Variables.BothHooked = false
- self.RightLog = nil
- self.LeftLog = nil
- self.Variables.Speed = 100
- self.Variables.LoggedSpeed = nil
- self.Variables.Force = Vector3.new(10000, 10000, 10000)
- self.Animations = {}
- local animator = self.Character:WaitForChild('Humanoid')
- self.Animations.rmT = animator:LoadAnimation(game.ReplicatedStorage.mRight)
- self.Animations.lmT = animator:LoadAnimation(game.ReplicatedStorage.mLeft)
- self.Animations.hookR = animator:LoadAnimation(game.ReplicatedStorage.Right)
- self.Animations.hookL = animator:LoadAnimation(game.ReplicatedStorage.Left)
- self.Animations.rmT.Looped = true
- self.Animations.lmT.Looped = true
- return self
- end
- function api:CreateHook(side, position)
- if side == 'Left' then
- if not self.Variables.LeftActive then
- self.Animations.hookL:Play()
- print(self.Animations.hookL.IsPlaying)
- local connection
- self.Variables.LeftLog = position
- self.Variables.LeftActive = true
- local Anchor = game.ReplicatedStorage.Hook:Clone()
- Anchor.Parent = self.Character.Hooks
- Anchor.Position = self.LeftGear.PrimaryPart.Position
- Anchor.Name = 'Left'
- local Beam = script.Beam:Clone()
- Beam.Parent = Anchor
- local att1 = Instance.new("Attachment", Anchor)
- local att2 = Instance.new("Attachment", self.Character.LeftGear.PrimaryPart)
- Beam.Attachment0 = att1
- Beam.Attachment1 = att2
- local Time = (position - Anchor.Position).Magnitude/600
- local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
- tween:Play()
- local rayP = RaycastParams.new()
- rayP.FilterType = Enum.RaycastFilterType.Blacklist
- rayP.FilterDescendantsInstances = {self.Character}
- local ray = workspace:Raycast(self.Character.LeftGear.PrimaryPart.Position, (position - self.LeftGear.PrimaryPart.Position).Unit * 400, rayP)
- if ray then
- print('ray hit: '..ray.Instance.Name)
- local hinge = Instance.new('WeldConstraint', Anchor)
- hinge.Part0 = Anchor
- hinge.Part1 = ray.Instance
- end
- if self.Variables.LeftActive then
- tween.Completed:Connect(function()
- Anchor.Anchored = false
- if self.Variables.LeftActive then
- self.Animations.lmT:Play()
- self.BodyVelocity.Parent = self.Character.HumanoidRootPart
- self.BodyGyro.Parent = self.Character.HumanoidRootPart
- connection = runservice.Heartbeat:Connect(function()
- if self.Variables.LeftActive == true and self.BodyVelocity.Parent == self.Character.HumanoidRootPart then
- print('Running')
- self.BodyVelocity.MaxForce = self.Variables.Force
- local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, Anchor.Position)
- self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
- self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, Anchor.Position)
- elseif not self.Variables.LeftActive then
- pcall(function()
- connection:Disconnect()
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
- self.Animations.lmT:Stop()
- end)
- end
- end)
- else
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy()
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- self.Animations.lmT:Stop()
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- self.Animations.lmT:Stop()
- end
- end
- end)
- else
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.lmT:Stop()
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end
- end
- end
- if side == 'Right' then
- if not self.Variables.RightActive then
- self.Animations.hookR:Play()
- local connection
- self.Variables.RightLog = position
- self.Variables.RightActive = true
- local Anchor = game.ReplicatedStorage.Hook:Clone()
- Anchor.Parent = self.Character.Hooks
- Anchor.Position = self.RightGear.PrimaryPart.Position
- Anchor.Name = 'Right'
- local Beam = script.Beam:Clone()
- Beam.Parent = Anchor
- local att1 = Instance.new("Attachment", Anchor)
- local att2 = Instance.new("Attachment", self.Character.RightGear.PrimaryPart)
- Beam.Attachment0 = att1
- Beam.Attachment1 = att2
- local Time = (position - Anchor.Position).Magnitude/600
- local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
- tween:Play()
- local rayP = RaycastParams.new()
- rayP.FilterType = Enum.RaycastFilterType.Blacklist
- rayP.FilterDescendantsInstances = {self.Character}
- local ray = workspace:Raycast(self.Character.LeftGear.PrimaryPart.Position, (position - self.LeftGear.PrimaryPart.Position).Unit * 400, rayP)
- if self.Variables.RightActive then
- tween.Completed:Connect(function()
- Anchor.Anchored = false
- if ray then
- print('ray hit: '..ray.Instance.Name)
- local hinge = Instance.new('WeldConstraint', Anchor)
- hinge.Part0 = Anchor
- hinge.Part1 = ray.Instance
- end
- if self.Variables.RightActive then
- self.Animations.rmT:Play()
- self.BodyVelocity.Parent = self.Character.HumanoidRootPart
- self.BodyGyro.Parent = self.Character.HumanoidRootPart
- connection = runservice.Heartbeat:Connect(function()
- if self.Variables.RightActive == true and self.BodyVelocity.Parent == self.Character.HumanoidRootPart then
- print('Running')
- self.BodyVelocity.MaxForce = self.Variables.Force
- local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, Anchor.Position)
- self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
- self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, Anchor.Position)
- elseif not self.Variables.RightActive then
- pcall(function()
- connection:Disconnect()
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
- self.Animations.rmT:Stop()
- end)
- end
- end)
- else
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.rmT:Stop()
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end
- end)
- else
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.rmT:Stop()
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end
- end
- end
- end
- function api:DestroyHook(s)
- self.Character.Humanoid.PlatformStand = false
- if s == 'Left' then
- self.Animations.lmT:Stop()
- self.Variables.LeftActive = false
- pcall(function()
- local velocity = self.Character.HumanoidRootPart:FindFirstChild('BodyVelocity')
- if velocity then
- velocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end)
- end
- if s == 'Right' then
- self.Animations.rmT:Stop()
- self.Variables.RightActive = false
- pcall(function()
- local velocity = self.Character.HumanoidRootPart:FindFirstChild('BodyVelocity')
- if velocity then
- velocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end)
- end
- end
- function api:Turn(way)
- self.Variables.LoggedSpeed = self.Variables.Speed
- self.Variables.Speed = 50
- if way == 'Right' then
- self.Variables.TurningRight = true
- local connection
- connection = runservice.Heartbeat:Connect(function()
- if self.Variables.TurningRight then
- self.Character.HumanoidRootPart.CFrame *= CFrame.new(1.7, 0, 0)
- else
- connection:Disconnect()
- end
- end)
- end
- if way == 'Left' then
- self.Variables.TurningLeft = true
- local connection
- connection = runservice.Heartbeat:Connect(function()
- if self.Variables.TurningLeft then
- self.Character.HumanoidRootPart.CFrame *= CFrame.new(-1.7, 0, 0)
- else
- connection:Disconnect()
- end
- end)
- end
- end
- function api:endTurn(way)
- self.Variables.Speed = self.Variables.LoggedSpeed
- if way == 'Right' then
- self.Variables.TurningRight = false
- end
- if way == 'Left' then
- self.Variables.TurningLeft = false
- end
- end
- function api:StartBoost()
- self.Variables.Speed = 200
- end
- function api:EndBoost()
- self.Variables.Speed = 100
- end
- function api:findDouble(position, t, extra)
- self.Variables.Speed = 150
- self.Variables.RightActive = false
- self.Variables.LeftActive = false
- local hook = self.Hooks:FindFirstChildWhichIsA('BasePart')
- local current
- local currN
- local s
- local logged
- if t == 'Right' then
- s = self.RightGear
- current = self.LeftGear
- currN = "Left"
- logged = self.Variables.LeftLog
- else
- s = self.LeftGear
- current = self.RightGear
- currN = 'Right'
- logged = self.Variables.RightLog
- end
- print(logged)
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- self.Variables.BothHooked = true
- local Anchor = game.ReplicatedStorage.Hook:Clone()
- Anchor.Parent = self.Hooks
- Anchor.Position = s.PrimaryPart.Position
- Anchor.Name = t
- local Beam = script.Beam:Clone()
- Beam.Parent = Anchor
- local att1 = Instance.new("Attachment", Anchor)
- local att2 = Instance.new("Attachment", s.PrimaryPart)
- Beam.Attachment0 = att1
- Beam.Attachment1 = att2
- local Time = (position - Anchor.Position).Magnitude/600
- local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
- tween:Play()
- local rayP = RaycastParams.new()
- rayP.FilterType = Enum.RaycastFilterType.Blacklist
- rayP.FilterDescendantsInstances = {self.Character}
- local ray = workspace:Raycast(s.PrimaryPart.Position, (position - s.PrimaryPart.Position).Unit * 400, rayP)
- local connection
- local anchor2 = game.ReplicatedStorage.Hook:Clone()
- anchor2.Position = logged
- anchor2.Parent = self.Hooks
- anchor2.Name = currN
- local beam = script.Beam:Clone()
- local at1 = Instance.new('Attachment', anchor2)
- local at2 = Instance.new('Attachment', current.PrimaryPart)
- beam.Parent = anchor2
- beam.Attachment0 = at1
- beam.Attachment1 = at2
- local newray = workspace:Raycast(current.PrimaryPart.Position, (position - current.PrimaryPart.Position).Unit * 400, rayP)
- if self.Variables.BothHooked then
- tween.Completed:Connect(function()
- Anchor.Anchored = false
- if ray then
- print('ray hit: '..ray.Instance.Name)
- local hinge = Instance.new('WeldConstraint', Anchor)
- hinge.Part0 = Anchor
- hinge.Part1 = ray.Instance
- end
- if newray then
- print('ray2 hit: '..newray.Instance.Name)
- local hinge = Instance.new('WeldConstraint', Anchor)
- hinge.Part0 = anchor2
- hinge.Part1 = newray.Instance
- end
- if self.Variables.BothHooked then
- self.BodyVelocity.Parent = self.Character.HumanoidRootPart
- self.BodyGyro.Parent = self.Character.HumanoidRootPart
- connection = runservice.Heartbeat:Connect(function()
- if self.Variables.BothHooked == true then
- local midPoint = Anchor.Position:Lerp(anchor2.Position, .5)
- print('Running')
- self.BodyVelocity.MaxForce = self.Variables.Force
- local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, midPoint)
- self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
- self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, midPoint)
- else
- pcall(function()
- connection:Disconnect()
- Anchor:Destroy() hook:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
- end)
- end
- end)
- else
- Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy()
- if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
- self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
- end
- if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
- self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
- end
- end
- end)
- end
- end
- function api:EndDouble()
- self.Variables.BothHooked = false
- self.Variables.Speed = 100
- for i, v in pairs(self.Hooks:GetChildren()) do
- v:Destroy()
- end
- end
- return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement