Advertisement
Guest User

Untitled

a guest
May 21st, 2022
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.51 KB | None | 0 0
  1. local api = {}
  2. local metatable = {__index = api}
  3. local tws = game["TweenService"]
  4. local runservice = game["Run Service"]
  5. function api.CreateModel(player)
  6. local self = {}
  7. setmetatable(self, metatable)
  8. self.Character = player.Character
  9. self.RightGear = self.Character.RightGear
  10. self.LeftGear = self.Character.LeftGear
  11. self.Hooks = Instance.new('Folder', self.Character)
  12. self.Hooks.Name = 'Hooks'
  13. self.BodyVelocity = Instance.new('BodyVelocity', self.Character)
  14. self.BodyGyro = Instance.new('BodyGyro', self.Character)
  15. self.BodyGyro.P = 1e+5
  16. self.BodyGyro.MaxTorque = Vector3.new(1e+3, 1e+3, 1e+3)
  17. self.Variables = {}
  18. self.Variables.RightActive = false
  19. self.Variables.LeftActive = false
  20. self.Variables.TurningRight = false
  21. self.Variables.TurningLeft = false
  22. self.Variables.BothHooked = false
  23. self.RightLog = nil
  24. self.LeftLog = nil
  25. self.Variables.Speed = 100
  26. self.Variables.LoggedSpeed = nil
  27. self.Variables.Force = Vector3.new(10000, 10000, 10000)
  28. self.Animations = {}
  29. local animator = self.Character:WaitForChild('Humanoid')
  30. self.Animations.rmT = animator:LoadAnimation(game.ReplicatedStorage.mRight)
  31. self.Animations.lmT = animator:LoadAnimation(game.ReplicatedStorage.mLeft)
  32. self.Animations.hookR = animator:LoadAnimation(game.ReplicatedStorage.Right)
  33. self.Animations.hookL = animator:LoadAnimation(game.ReplicatedStorage.Left)
  34. self.Animations.rmT.Looped = true
  35. self.Animations.lmT.Looped = true
  36. return self
  37. end
  38. function api:CreateHook(side, position)
  39.  
  40. if side == 'Left' then
  41. if not self.Variables.LeftActive then
  42. self.Animations.hookL:Play()
  43. print(self.Animations.hookL.IsPlaying)
  44.  
  45. local connection
  46. self.Variables.LeftLog = position
  47. self.Variables.LeftActive = true
  48. local Anchor = game.ReplicatedStorage.Hook:Clone()
  49. Anchor.Parent = self.Character.Hooks
  50. Anchor.Position = self.LeftGear.PrimaryPart.Position
  51. Anchor.Name = 'Left'
  52. local Beam = script.Beam:Clone()
  53. Beam.Parent = Anchor
  54. local att1 = Instance.new("Attachment", Anchor)
  55. local att2 = Instance.new("Attachment", self.Character.LeftGear.PrimaryPart)
  56. Beam.Attachment0 = att1
  57. Beam.Attachment1 = att2
  58. local Time = (position - Anchor.Position).Magnitude/600
  59. local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
  60. tween:Play()
  61. local rayP = RaycastParams.new()
  62. rayP.FilterType = Enum.RaycastFilterType.Blacklist
  63. rayP.FilterDescendantsInstances = {self.Character}
  64. local ray = workspace:Raycast(self.Character.LeftGear.PrimaryPart.Position, (position - self.LeftGear.PrimaryPart.Position).Unit * 400, rayP)
  65.  
  66. if ray then
  67.  
  68. print('ray hit: '..ray.Instance.Name)
  69.  
  70.  
  71. local hinge = Instance.new('WeldConstraint', Anchor)
  72. hinge.Part0 = Anchor
  73. hinge.Part1 = ray.Instance
  74. end
  75. if self.Variables.LeftActive then
  76. tween.Completed:Connect(function()
  77. Anchor.Anchored = false
  78.  
  79. if self.Variables.LeftActive then
  80. self.Animations.lmT:Play()
  81. self.BodyVelocity.Parent = self.Character.HumanoidRootPart
  82. self.BodyGyro.Parent = self.Character.HumanoidRootPart
  83. connection = runservice.Heartbeat:Connect(function()
  84. if self.Variables.LeftActive == true and self.BodyVelocity.Parent == self.Character.HumanoidRootPart then
  85. print('Running')
  86. self.BodyVelocity.MaxForce = self.Variables.Force
  87. local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, Anchor.Position)
  88. self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
  89. self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, Anchor.Position)
  90. elseif not self.Variables.LeftActive then
  91.  
  92.  
  93. pcall(function()
  94. connection:Disconnect()
  95. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
  96. self.Animations.lmT:Stop()
  97. end)
  98.  
  99.  
  100. end
  101. end)
  102.  
  103. else
  104. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy()
  105. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  106. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  107. self.Animations.lmT:Stop()
  108. end
  109. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  110. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  111. self.Animations.lmT:Stop()
  112. end
  113. end
  114.  
  115. end)
  116. else
  117. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.lmT:Stop()
  118. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  119. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  120. end
  121. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  122. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  123. end
  124. end
  125. end
  126. end
  127. if side == 'Right' then
  128. if not self.Variables.RightActive then
  129. self.Animations.hookR:Play()
  130. local connection
  131. self.Variables.RightLog = position
  132. self.Variables.RightActive = true
  133. local Anchor = game.ReplicatedStorage.Hook:Clone()
  134. Anchor.Parent = self.Character.Hooks
  135. Anchor.Position = self.RightGear.PrimaryPart.Position
  136. Anchor.Name = 'Right'
  137. local Beam = script.Beam:Clone()
  138. Beam.Parent = Anchor
  139. local att1 = Instance.new("Attachment", Anchor)
  140. local att2 = Instance.new("Attachment", self.Character.RightGear.PrimaryPart)
  141. Beam.Attachment0 = att1
  142. Beam.Attachment1 = att2
  143. local Time = (position - Anchor.Position).Magnitude/600
  144. local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
  145. tween:Play()
  146. local rayP = RaycastParams.new()
  147. rayP.FilterType = Enum.RaycastFilterType.Blacklist
  148. rayP.FilterDescendantsInstances = {self.Character}
  149. local ray = workspace:Raycast(self.Character.LeftGear.PrimaryPart.Position, (position - self.LeftGear.PrimaryPart.Position).Unit * 400, rayP)
  150.  
  151.  
  152. if self.Variables.RightActive then
  153. tween.Completed:Connect(function()
  154. Anchor.Anchored = false
  155. if ray then
  156.  
  157. print('ray hit: '..ray.Instance.Name)
  158.  
  159.  
  160. local hinge = Instance.new('WeldConstraint', Anchor)
  161. hinge.Part0 = Anchor
  162. hinge.Part1 = ray.Instance
  163. end
  164. if self.Variables.RightActive then
  165. self.Animations.rmT:Play()
  166. self.BodyVelocity.Parent = self.Character.HumanoidRootPart
  167. self.BodyGyro.Parent = self.Character.HumanoidRootPart
  168. connection = runservice.Heartbeat:Connect(function()
  169. if self.Variables.RightActive == true and self.BodyVelocity.Parent == self.Character.HumanoidRootPart then
  170. print('Running')
  171. self.BodyVelocity.MaxForce = self.Variables.Force
  172. local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, Anchor.Position)
  173. self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
  174. self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, Anchor.Position)
  175. elseif not self.Variables.RightActive then
  176.  
  177.  
  178. pcall(function()
  179. connection:Disconnect()
  180. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
  181. self.Animations.rmT:Stop()
  182. end)
  183.  
  184. end
  185.  
  186. end)
  187.  
  188. else
  189. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.rmT:Stop()
  190. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  191. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  192. end
  193. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  194. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  195. end
  196. end
  197.  
  198. end)
  199. else
  200. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.Animations.rmT:Stop()
  201. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  202. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  203. end
  204. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  205. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  206. end
  207. end
  208. end
  209. end
  210. end
  211. function api:DestroyHook(s)
  212. self.Character.Humanoid.PlatformStand = false
  213.  
  214. if s == 'Left' then
  215. self.Animations.lmT:Stop()
  216. self.Variables.LeftActive = false
  217. pcall(function()
  218. local velocity = self.Character.HumanoidRootPart:FindFirstChild('BodyVelocity')
  219. if velocity then
  220. velocity.Parent = self.Character
  221. end
  222. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  223. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  224. end
  225. end)
  226. end
  227. if s == 'Right' then
  228. self.Animations.rmT:Stop()
  229. self.Variables.RightActive = false
  230. pcall(function()
  231. local velocity = self.Character.HumanoidRootPart:FindFirstChild('BodyVelocity')
  232. if velocity then
  233. velocity.Parent = self.Character
  234. end
  235. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  236. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  237. end
  238. end)
  239. end
  240. end
  241. function api:Turn(way)
  242. self.Variables.LoggedSpeed = self.Variables.Speed
  243. self.Variables.Speed = 50
  244. if way == 'Right' then
  245. self.Variables.TurningRight = true
  246. local connection
  247. connection = runservice.Heartbeat:Connect(function()
  248. if self.Variables.TurningRight then
  249. self.Character.HumanoidRootPart.CFrame *= CFrame.new(1.7, 0, 0)
  250. else
  251. connection:Disconnect()
  252. end
  253. end)
  254. end
  255. if way == 'Left' then
  256. self.Variables.TurningLeft = true
  257. local connection
  258. connection = runservice.Heartbeat:Connect(function()
  259. if self.Variables.TurningLeft then
  260. self.Character.HumanoidRootPart.CFrame *= CFrame.new(-1.7, 0, 0)
  261. else
  262. connection:Disconnect()
  263. end
  264. end)
  265. end
  266. end
  267. function api:endTurn(way)
  268. self.Variables.Speed = self.Variables.LoggedSpeed
  269. if way == 'Right' then
  270. self.Variables.TurningRight = false
  271. end
  272. if way == 'Left' then
  273. self.Variables.TurningLeft = false
  274. end
  275. end
  276. function api:StartBoost()
  277. self.Variables.Speed = 200
  278. end
  279. function api:EndBoost()
  280. self.Variables.Speed = 100
  281. end
  282. function api:findDouble(position, t, extra)
  283. self.Variables.Speed = 150
  284. self.Variables.RightActive = false
  285. self.Variables.LeftActive = false
  286. local hook = self.Hooks:FindFirstChildWhichIsA('BasePart')
  287. local current
  288. local currN
  289. local s
  290. local logged
  291. if t == 'Right' then
  292. s = self.RightGear
  293. current = self.LeftGear
  294. currN = "Left"
  295. logged = self.Variables.LeftLog
  296. else
  297. s = self.LeftGear
  298. current = self.RightGear
  299. currN = 'Right'
  300. logged = self.Variables.RightLog
  301. end
  302. print(logged)
  303. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  304. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  305. end
  306. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  307. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  308. end
  309. self.Variables.BothHooked = true
  310.  
  311. local Anchor = game.ReplicatedStorage.Hook:Clone()
  312. Anchor.Parent = self.Hooks
  313. Anchor.Position = s.PrimaryPart.Position
  314. Anchor.Name = t
  315. local Beam = script.Beam:Clone()
  316. Beam.Parent = Anchor
  317. local att1 = Instance.new("Attachment", Anchor)
  318. local att2 = Instance.new("Attachment", s.PrimaryPart)
  319. Beam.Attachment0 = att1
  320. Beam.Attachment1 = att2
  321. local Time = (position - Anchor.Position).Magnitude/600
  322. local tween = tws:Create(Anchor, TweenInfo.new(Time), {Position = position})
  323. tween:Play()
  324. local rayP = RaycastParams.new()
  325. rayP.FilterType = Enum.RaycastFilterType.Blacklist
  326. rayP.FilterDescendantsInstances = {self.Character}
  327. local ray = workspace:Raycast(s.PrimaryPart.Position, (position - s.PrimaryPart.Position).Unit * 400, rayP)
  328. local connection
  329. local anchor2 = game.ReplicatedStorage.Hook:Clone()
  330. anchor2.Position = logged
  331. anchor2.Parent = self.Hooks
  332. anchor2.Name = currN
  333. local beam = script.Beam:Clone()
  334. local at1 = Instance.new('Attachment', anchor2)
  335. local at2 = Instance.new('Attachment', current.PrimaryPart)
  336. beam.Parent = anchor2
  337. beam.Attachment0 = at1
  338. beam.Attachment1 = at2
  339. local newray = workspace:Raycast(current.PrimaryPart.Position, (position - current.PrimaryPart.Position).Unit * 400, rayP)
  340. if self.Variables.BothHooked then
  341. tween.Completed:Connect(function()
  342. Anchor.Anchored = false
  343. if ray then
  344.  
  345. print('ray hit: '..ray.Instance.Name)
  346.  
  347.  
  348. local hinge = Instance.new('WeldConstraint', Anchor)
  349. hinge.Part0 = Anchor
  350. hinge.Part1 = ray.Instance
  351. end
  352. if newray then
  353.  
  354. print('ray2 hit: '..newray.Instance.Name)
  355.  
  356.  
  357. local hinge = Instance.new('WeldConstraint', Anchor)
  358. hinge.Part0 = anchor2
  359. hinge.Part1 = newray.Instance
  360. end
  361. if self.Variables.BothHooked then
  362. self.BodyVelocity.Parent = self.Character.HumanoidRootPart
  363. self.BodyGyro.Parent = self.Character.HumanoidRootPart
  364.  
  365. connection = runservice.Heartbeat:Connect(function()
  366. if self.Variables.BothHooked == true then
  367. local midPoint = Anchor.Position:Lerp(anchor2.Position, .5)
  368.  
  369. print('Running')
  370. self.BodyVelocity.MaxForce = self.Variables.Force
  371. local target = CFrame.lookAt(self.Character.HumanoidRootPart.Position, midPoint)
  372. self.BodyVelocity.Velocity = (-target.ZVector * self.Variables.Speed)
  373. self.BodyGyro.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position, midPoint)
  374. else
  375. pcall(function()
  376. connection:Disconnect()
  377. Anchor:Destroy() hook:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy() self.BodyVelocity.Parent = self.Character self.BodyGyro.Parent = self.Character
  378.  
  379. end)
  380. end
  381. end)
  382.  
  383. else
  384. Anchor:Destroy() Beam:Destroy() att1:Destroy() att2:Destroy()
  385. if self.Character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
  386. self.Character.HumanoidRootPart.BodyVelocity.Parent = self.Character
  387. end
  388. if self.Character.HumanoidRootPart:FindFirstChild("BodyGyro") then
  389. self.Character.HumanoidRootPart.BodyGyro.Parent = self.Character
  390. end
  391. end
  392.  
  393. end)
  394. end
  395. end
  396. function api:EndDouble()
  397. self.Variables.BothHooked = false
  398. self.Variables.Speed = 100
  399. for i, v in pairs(self.Hooks:GetChildren()) do
  400. v:Destroy()
  401. end
  402. end
  403.  
  404. return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement