StenHisDirt

HardDrag

Oct 1st, 2019
43,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.48 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local Character = player.Character or player.CharacterAdded:wait()
  3. local Humanoid = Character:WaitForChild("Humanoid")
  4. local walkSpeed = Humanoid.WalkSpeed
  5. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Disabled = true
  6. _G.dragRangeMin = 5
  7. fivefour = coroutine.wrap(function()
  8. EKey = false
  9. QKey = false
  10. player:GetMouse().KeyDown:connect(function(key)
  11. if string.lower(key) == "e" then
  12. EKey = true
  13. elseif string.lower(key) == "q" then
  14. QKey = true
  15. end
  16. end)
  17. player:GetMouse().KeyUp:connect(function(key)
  18. if string.lower(key) == "e" then
  19. EKey = false
  20. elseif string.lower(key) == "q" then
  21. QKey = false
  22. end
  23. end)
  24. while wait(0.1) do
  25. if EKey then
  26. F = FVal
  27. FVal = FVal + 1000
  28. ChangeForce(F+1000)
  29. print(F)
  30. end
  31. if QKey then
  32. F = FVal
  33. FVal = FVal - 1000
  34. ChangeForce(F-1000)
  35. print(F)
  36. end
  37. end
  38.  
  39. end)
  40. fivefour()
  41. local dragPart = Instance.new("Part",game.Players.LocalPlayer.PlayerGui)--game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Dragger
  42. dragPart.Size = Vector3.new(0.2,0.2,0.2)
  43. dragPart.BrickColor = BrickColor.new("Really red")
  44. player.CharacterAdded:connect(function()
  45. Character = player.Character
  46. Humanoid = Character:WaitForChild("Humanoid")
  47. Humanoid.Died:connect(function()
  48. dragPart.Parent = nil
  49. end)
  50. end)
  51.  
  52. wait(1)
  53. local dragRangeMax = 10000
  54. local dragRangeMin = _G.dragRangeMin
  55.  
  56. local camera = workspace.CurrentCamera
  57. local mouse = player:GetMouse()
  58.  
  59. local button1Down = false
  60. local dragRange = dragRangeMax
  61. FVal = 80000
  62. local bodyPosition = Instance.new("BodyPosition", dragPart)
  63. bodyPosition.maxForce = Vector3.new(1, 1, 1) * FVal
  64. bodyPosition.D = 1000
  65. bodyPosition.P = 4000
  66. function ChangeForce(F)
  67. if F > 0 then
  68. F = bodyPosition.maxForce.X+F
  69. bodyPosition.maxForce = Vector3.new(1, 1, 1) * F
  70. else
  71. F = bodyPosition.maxForce.X-F
  72. bodyPosition.maxForce = Vector3.new(1, 1, 1) * F
  73. end
  74. end
  75.  
  76. local bodyGyro = Instance.new("BodyGyro", dragPart)
  77. bodyGyro.maxTorque = Vector3.new(1, 1, 1) * 200 --4000 -- * 0.000012
  78. bodyGyro.P = 1200
  79. bodyGyro.D = 140 --15
  80.  
  81. --bodyPosition.P = bodyPosition.P * 1/19
  82. --bodyPosition.D = bodyPosition.D * 1/19
  83. --bodyGyro.P = bodyGyro.P * 1/19
  84. --bodyGyro.D = bodyGyro.D * 1/19
  85.  
  86. local rotateCFrame = CFrame.new()
  87.  
  88. local weld = Instance.new("Weld", dragPart)
  89.  
  90. --local interactPermission = require(game.ReplicatedStorage.Interaction.InteractionPermission)
  91. local clientIsDragging = game.ReplicatedStorage.Interaction.ClientIsDragging
  92.  
  93. local carryAnimationTrack
  94.  
  95.  
  96. --------------------------------[[ Drag Main ]]------------------------------------
  97.  
  98. local draggingPart = false
  99.  
  100. function click()
  101. button1Down = true
  102.  
  103. local targetObject = game.Players.LocalPlayer:GetMouse().Target
  104. if not canDrag(targetObject) then
  105. return
  106. end
  107.  
  108. local mouseHit = game.Players.LocalPlayer:GetMouse().Hit.p
  109. if (mouseHit - Character.Head.Position).magnitude > dragRangeMax then
  110. return
  111. end
  112.  
  113. initializeDrag(targetObject, mouseHit)
  114. rotateCFrame = CFrame.new()
  115.  
  116. carryAnimationTrack:Play(0.1, 1, 1)
  117.  
  118. local dragIsFailing = 0
  119. local dragTime = 0
  120.  
  121.  
  122. while button1Down and canDrag(targetObject) do
  123. local desiredPos = Character.Head.Position + (game.Players.LocalPlayer:GetMouse().Hit.p - Character.Head.Position).unit * dragRange
  124.  
  125. local dragRay = Ray.new(Character.Head.Position, desiredPos - Character.Head.Position)
  126. local part, pos = workspace:FindPartOnRayWithIgnoreList(dragRay, {Character, dragPart, targetObject.Parent})
  127.  
  128. if part then
  129. desiredPos = pos
  130. end
  131.  
  132. if (camera.CoordinateFrame.p - Character.Head.Position).magnitude > 2 then
  133. desiredPos = desiredPos + Vector3.new(0, 1.8, 0)
  134. end
  135.  
  136. moveDrag(desiredPos)
  137. bodyGyro.cframe = CFrame.new(dragPart.Position, camera.CoordinateFrame.p) * rotateCFrame
  138.  
  139. local targParent = findHighestParent(targetObject) or targetObject
  140.  
  141. local attemptingToSurf = false
  142. for _, check in pairs({{Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))},
  143. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))},
  144. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0)).p, Vector3.new(0, -2, 0))},
  145. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))},
  146. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))},
  147.  
  148. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))},
  149. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0.6)).p, Vector3.new(0, -2, 0))},
  150. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))},
  151.  
  152. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))},
  153. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, -0.6)).p, Vector3.new(0, -2, 0))},
  154. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))},
  155.  
  156. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector), State = Enum.HumanoidStateType.Climbing},
  157. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector), State = Enum.HumanoidStateType.Climbing},
  158. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector), State = Enum.HumanoidStateType.Climbing},
  159. {Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector), State = Enum.HumanoidStateType.Climbing}
  160.  
  161. }) do
  162.  
  163. local ray = check.Ray
  164. local part, _ = workspace:FindPartOnRayWithIgnoreList(ray, {Character})
  165. local op = part
  166. part = part and findHighestParent(part)
  167.  
  168. if part and (not check.State or Humanoid:GetState() == check.State) then
  169. if part == targParent then
  170. attemptingToSurf = true
  171. else
  172. for _, connectedPart in pairs(op:GetConnectedParts(true)) do
  173.  
  174. if connectedPart == targetObject--[[targParent]] then
  175. attemptingToSurf = true
  176. break
  177. end
  178. end
  179. end
  180.  
  181. if attemptingToSurf then
  182. break
  183. end
  184. end
  185. end
  186.  
  187.  
  188.  
  189.  
  190.  
  191. local falling = Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.FallingDown--not part1 and not part2
  192.  
  193.  
  194. if attemptingToSurf then
  195. dragIsFailing = 0
  196. elseif falling then
  197. dragIsFailing = 0
  198. elseif (dragPart.Position - desiredPos).magnitude > 5 then
  199. dragIsFailing = 0
  200. else
  201. dragIsFailing = 0
  202. end
  203. if dragIsFailing > 16 then
  204. break
  205. end
  206.  
  207.  
  208. if dragTime % 10 == 0 and targParent.Parent:FindFirstChild("BedInfo") and targParent.Parent:FindFirstChild("Main") then
  209. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Parent.Scripts.VehicleControl.SetVehicleOwnership:Fire(targParent.Parent.Main)
  210. end
  211.  
  212. clientIsDragging:FireServer(targParent.Parent)
  213.  
  214. wait()
  215. dragTime = 0
  216. end
  217.  
  218. carryAnimationTrack:Stop()
  219.  
  220. endDrag()
  221. end
  222.  
  223.  
  224. function findHighestParent(child)
  225. if not child or not child.Parent or child.Parent == workspace then
  226. return nil
  227. end
  228.  
  229. local ret = child.Parent:FindFirstChild("Owner") and child
  230. return findHighestParent(child.Parent) or ret
  231. end
  232.  
  233.  
  234.  
  235. function clickEnded()
  236. button1Down = false
  237. end
  238.  
  239. function holdDistanceChanged()
  240. dragRange = dragRangeMax--[[_G.dragRangeMin + (1 - dist) * (dragRangeMax - _G.dragRangeMin)]]
  241. end
  242.  
  243.  
  244. function canDrag(targetObject)
  245.  
  246.  
  247. if not (targetObject and not targetObject.Anchored and targetObject.Parent and Humanoid.Health > 0) then -- General conditions
  248. return false
  249. end
  250.  
  251. if targetObject.Name == "LeafPart" then
  252. return false
  253. end
  254.  
  255. local originTargetObject = targetObject
  256. targetObject = findHighestParent(targetObject) or targetObject
  257.  
  258. bodyGyro.Parent = dragPart
  259.  
  260.  
  261. --[[if not (targetObject.Parent:FindFirstChild("Owner") or targetObject.Parent.Parent:FindFirstChild("Owner")) then
  262. return otherDraggable(targetObject, originTargetObject)
  263. end]]
  264.  
  265. if targetObject.Parent:FindFirstChild("Owner") or targetObject.Parent.Parent:FindFirstChild("Owner") then
  266. return true
  267. end
  268.  
  269. if targetObject.Parent:FindFirstChild("TreeClass") then -- Wood class
  270. return true
  271. end
  272. if targetObject.Parent:FindFirstChild("BoxItemName") then -- Shop items
  273. return true
  274. end
  275. if targetObject.Parent:FindFirstChild("PurchasedBoxItemName") then -- Purchased box items
  276. return true
  277. end
  278. if targetObject.Parent:FindFirstChild("Handle") then -- Tool items
  279. return true
  280. end
  281.  
  282. return otherDraggable(targetObject, originTargetObject)
  283. end
  284.  
  285. function otherDraggable(targetObject, originTargetObject)
  286. local draggable = targetObject and targetObject.Parent and targetObject.Parent:FindFirstChild("DraggableItem") or originTargetObject and originTargetObject.Parent and originTargetObject.Parent:FindFirstChild("DraggableItem")
  287. if draggable then -- Other stuff
  288. if draggable:FindFirstChild("NoRotate") then
  289. bodyGyro.Parent = nil
  290. end
  291. return true
  292. end
  293. end
  294.  
  295. function initializeDrag(targetObject,mouseHit)
  296. draggingPart = true
  297. mouse.TargetFilter = targetObject and findHighestParent(targetObject) and findHighestParent(targetObject).Parent or targetObject
  298.  
  299. dragPart.CFrame = CFrame.new(mouseHit, camera.CoordinateFrame.p)
  300.  
  301. weld.Part0 = dragPart
  302. weld.Part1 = targetObject
  303. weld.C0 = CFrame.new(mouseHit,camera.CoordinateFrame.p):inverse() * targetObject.CFrame
  304. weld.Parent = dragPart
  305.  
  306. dragPart.Parent = workspace
  307. end
  308.  
  309. function endDrag()
  310. mouse.TargetFilter = nil
  311. dragPart.Parent = nil
  312. draggingPart = false
  313. end
  314.  
  315. --------------------------------[[ Do Prompt ]]------------------------------------
  316.  
  317.  
  318. local dragGuiState = ""
  319. function interactLoop()
  320. while true do
  321. wait()
  322.  
  323. local newState = ""
  324.  
  325. local mouseHit = game.Players.LocalPlayer:GetMouse().Hit.p
  326. local targetObject = game.Players.LocalPlayer:GetMouse().Target
  327.  
  328.  
  329. if draggingPart then
  330. newState = "Dragging"
  331. elseif canDrag(targetObject) and not button1Down and (mouseHit - Character.Head.Position).magnitude < dragRangeMax then
  332. newState = "Mouseover"
  333. end
  334.  
  335. if true then-- not (newState == dragGuiState) then
  336. dragGuiState = newState
  337. setPlatformControls()
  338.  
  339. if dragGuiState == "" then
  340. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.Visible = false
  341. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.Visible = false
  342. elseif dragGuiState == "Mouseover" then
  343. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.Visible = true
  344. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.Visible = false
  345. elseif dragGuiState == "Dragging" then
  346. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.Visible = false
  347. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.Visible = not (bodyGyro.Parent == nil) and (not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 1)
  348. end
  349. end
  350.  
  351. end
  352. end
  353.  
  354.  
  355. --------------------------------[[ Drag Moving ]]------------------------------------
  356.  
  357.  
  358. function moveDrag(pos)
  359. bodyPosition.position = pos
  360. end
  361. local rotateSpeedReduce = 0.036
  362.  
  363. local lastRotateTick
  364. function crotate(amount, speed)
  365.  
  366. if not draggingPart then
  367. if not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2 then
  368. Humanoid.WalkSpeed = walkSpeed
  369. end
  370. return
  371. end
  372.  
  373. if Humanoid.WalkSpeed > 1 then
  374. walkSpeed = Humanoid.WalkSpeed
  375. Humanoid.WalkSpeed = 0
  376. end
  377.  
  378. lastRotateTick = tick()
  379. local thisRotateTick = lastRotateTick
  380.  
  381. while draggingPart and amount.magnitude > 0 and lastRotateTick == thisRotateTick do
  382. rotateCFrame = CFrame.Angles(0, -amount.X * rotateSpeedReduce, 0) * CFrame.Angles(amount.Y * rotateSpeedReduce, 0, 0) * rotateCFrame
  383. wait()
  384. end
  385.  
  386. if amount.magnitude == 0 then
  387. if not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2 then
  388. Humanoid.WalkSpeed = walkSpeed
  389. end
  390. end
  391. end
  392.  
  393. --------------------------------[[ User Input ]]------------------------------------
  394.  
  395. wait(1)
  396.  
  397. carryAnimationTrack = Humanoid:LoadAnimation(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger:WaitForChild("CarryItem"))
  398.  
  399. --input = require(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Parent:WaitForChild("Scripts"):WaitForChild("UserInput"))
  400.  
  401. game.Players.LocalPlayer:GetMouse().Button1Down:connect(function()
  402. click()
  403. holdDistanceChanged()
  404. end)
  405. game.Players.LocalPlayer:GetMouse().Button1Up:connect(function()
  406. clickEnded()
  407. end)
  408. --input.ClickBegan(click, holdDistanceChanged)
  409. --input.ClickEnded(clickEnded)
  410.  
  411. --input.Rotate(crotate)
  412.  
  413.  
  414. function setPlatformControls()
  415. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.PlatformButton.PC.Value
  416. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanDrag.PlatformButton.KeyLabel.Text = "CLICK"
  417. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.PlatformButton.PC.Value
  418. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.CanRotate.PlatformButton.KeyLabel.Text = "SHIFT + WASD"
  419. end
  420.  
  421.  
  422. interactLoop()
Add Comment
Please, Sign In to add comment