Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Disabled = true
  2.  
  3. local player = game.Players.LocalPlayer
  4. local Character = player.Character or player.CharacterAdded:wait()
  5. local Humanoid = Character:WaitForChild("Humanoid")
  6. local walkSpeed = Humanoid.WalkSpeed
  7. local dragPart = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger:FindFirstChild("Dragger") or game.StarterGui.ItemDraggingGUI.Dragger:FindFirstChild("Dragger"):Clone()
  8. dragPart.Parent = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger
  9. player.CharacterAdded:connect(function()
  10. Character = player.Character
  11. Humanoid = Character:WaitForChild("Humanoid")
  12. Humanoid.Died:connect(function()
  13. dragPart.Parent = nil
  14. end)
  15. end)
  16. wait(1)
  17. local dragRangeMax = 10e6
  18. local dragRangeMin = 7
  19. local camera = workspace.CurrentCamera
  20. local mouse = player:GetMouse()
  21. local button1Down = false
  22. local dragRange = dragRangeMax
  23. local bodyPosition = Instance.new("BodyPosition", dragPart)
  24. bodyPosition.maxForce = Vector3.new(10e9,10e9,10e9)
  25. bodyPosition.D = 800
  26. local bodyGyro = Instance.new("BodyGyro", dragPart)
  27. bodyGyro.maxTorque = Vector3.new(1, 1, 1) * 200
  28. bodyGyro.P = 1200
  29. bodyGyro.D = 140
  30. local rotateCFrame = CFrame.new()
  31. local weld = Instance.new("Weld", dragPart)
  32. local interactPermission = require(game.ReplicatedStorage.Interaction.InteractionPermission)
  33. local clientIsDragging = game.ReplicatedStorage.Interaction.ClientIsDragging
  34. local carryAnimationTrack
  35. local draggingPart = false
  36. function click()
  37. button1Down = true
  38. local targetObject = input.GetMouseTarget()
  39. if not canDrag(targetObject) then
  40. return
  41. end
  42. local mouseHit = input.GetMouseHit().p
  43. if (mouseHit - Character.Head.Position).magnitude > dragRangeMax then
  44. return
  45. end
  46. initializeDrag(targetObject, mouseHit)
  47. rotateCFrame = CFrame.new()
  48. carryAnimationTrack:Play(0.1, 1, 1)
  49. local dragIsFailing = 0
  50. local dragTime = 0
  51. while button1Down and canDrag(targetObject) do
  52. local desiredPos = Character.Head.Position + (input.GetMouseHit().p - Character.Head.Position).unit * dragRange
  53. local dragRay = Ray.new(Character.Head.Position, desiredPos - Character.Head.Position)
  54. local part, pos = workspace:FindPartOnRayWithIgnoreList(dragRay, {
  55. Character,
  56. dragPart,
  57. targetObject.Parent
  58. })
  59. if part then
  60. desiredPos = pos
  61. end
  62. if (camera.CoordinateFrame.p - Character.Head.Position).magnitude > 2 then
  63. desiredPos = desiredPos + Vector3.new(0, 1.8, 0)
  64. end
  65. moveDrag(desiredPos)
  66. bodyGyro.cframe = CFrame.new(dragPart.Position, camera.CoordinateFrame.p) * rotateCFrame
  67. local targParent = findHighestParent(targetObject) or targetObject
  68. local attemptingToSurf = false
  69. for _, check in pairs({
  70. {
  71. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))
  72. },
  73. {
  74. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))
  75. },
  76. {
  77. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0)).p, Vector3.new(0, -2, 0))
  78. },
  79. {
  80. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))
  81. },
  82. {
  83. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))
  84. },
  85. {
  86. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
  87. },
  88. {
  89. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
  90. },
  91. {
  92. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
  93. },
  94. {
  95. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
  96. },
  97. {
  98. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
  99. },
  100. {
  101. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
  102. },
  103. {
  104. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
  105. State = Enum.HumanoidStateType.Climbing
  106. },
  107. {
  108. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
  109. State = Enum.HumanoidStateType.Climbing
  110. },
  111. {
  112. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
  113. State = Enum.HumanoidStateType.Climbing
  114. },
  115. {
  116. Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
  117. State = Enum.HumanoidStateType.Climbing
  118. }
  119. }) do
  120. local ray = check.Ray
  121. local part, _ = workspace:FindPartOnRayWithIgnoreList(ray, {Character})
  122. local op = part
  123. part = part and findHighestParent(part)
  124. if part and (not check.State or Humanoid:GetState() == check.State) then
  125. if part == targParent then
  126. attemptingToSurf = true
  127. else
  128. for _, connectedPart in pairs(op:GetConnectedParts(true)) do
  129. if connectedPart == targetObject then
  130. attemptingToSurf = true
  131. break
  132. end
  133. end
  134. end
  135. end
  136. end
  137. local falling = Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.FallingDown
  138.  
  139. dragIsFailing = 0
  140.  
  141. if dragTime % 10 == 0 and targParent.Parent:FindFirstChild("BedInfo") and targParent.Parent:FindFirstChild("Main") then
  142. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.Parent.Scripts.VehicleControl.SetVehicleOwnership:Fire(targParent.Parent.Main)
  143. end
  144. clientIsDragging:FireServer(targParent.Parent)
  145. wait()
  146. dragTime = dragTime + 1
  147. end
  148. carryAnimationTrack:Stop()
  149. endDrag()
  150. end
  151. function findHighestParent(child)
  152. if not (child and child.Parent) or child.Parent == workspace then
  153. return nil
  154. end
  155. local ret = child.Parent:FindFirstChild("Owner") and child
  156. return findHighestParent(child.Parent) or ret
  157. end
  158. function clickEnded()
  159. button1Down = false
  160. end
  161. function holdDistanceChanged(dist)
  162. dragRange = dragRangeMin + (1 - dist) * (dragRangeMax - dragRangeMin)
  163. end
  164. function canDrag(targetObject)
  165. for _, instance in pairs(Character:GetChildren()) do
  166. if instance:IsA("Tool") then
  167. return false
  168. end
  169. end
  170. if not (targetObject and not targetObject.Anchored and targetObject.Parent) or not (Humanoid.Health > 0) then
  171. return false
  172. end
  173. if targetObject.Name == "LeafPart" then
  174. return false
  175. end
  176. local originTargetObject = targetObject
  177. targetObject = findHighestParent(targetObject) or targetObject
  178. if game.Players:GetPlayerFromCharacter(targetObject.Parent.Parent) then
  179. return false
  180. end
  181. bodyGyro.Parent = dragPart
  182. if not targetObject.Parent:FindFirstChild("Owner") then
  183. return otherDraggable(targetObject, originTargetObject)
  184. end
  185. if not interactPermission:UserCanInteract(player, targetObject.Parent) then
  186. return false
  187. end
  188. if targetObject.Parent:FindFirstChild("TreeClass") then
  189. return true
  190. end
  191. if targetObject.Parent:FindFirstChild("BoxItemName") then
  192. return true
  193. end
  194. if targetObject.Parent:FindFirstChild("PurchasedBoxItemName") then
  195. return true
  196. end
  197. if targetObject.Parent:FindFirstChild("Handle") then
  198. return true
  199. end
  200. return otherDraggable(targetObject, originTargetObject)
  201. end
  202. function otherDraggable(targetObject, originTargetObject)
  203. local draggable = targetObject and targetObject.Parent and targetObject.Parent:FindFirstChild("DraggableItem") or originTargetObject and originTargetObject.Parent and originTargetObject.Parent:FindFirstChild("DraggableItem")
  204. if draggable then
  205. if draggable:FindFirstChild("NoRotate") then
  206. bodyGyro.Parent = nil
  207. end
  208. return true
  209. end
  210. end
  211. function initializeDrag(targetObject, mouseHit)
  212. draggingPart = true
  213. mouse.TargetFilter = targetObject and findHighestParent(targetObject) and findHighestParent(targetObject).Parent or targetObject
  214. dragPart.CFrame = CFrame.new(mouseHit, camera.CoordinateFrame.p)
  215. weld.Part0 = dragPart
  216. weld.Part1 = targetObject
  217. weld.C0 = CFrame.new(mouseHit, camera.CoordinateFrame.p):inverse() * targetObject.CFrame
  218. weld.Parent = dragPart
  219. dragPart.Parent = workspace
  220. end
  221. function endDrag()
  222. mouse.TargetFilter = nil
  223. dragPart.Parent = nil
  224. draggingPart = false
  225. end
  226. local dragGuiState = ""
  227. function interactLoop()
  228. while true do
  229. wait()
  230. local newState = ""
  231. local mouseHit = input.GetMouseHit().p
  232. local targetObject = input.GetMouseTarget()
  233. if draggingPart then
  234. newState = "Dragging"
  235. elseif canDrag(targetObject) and not button1Down and (mouseHit - Character.Head.Position).magnitude < dragRangeMax then
  236. newState = "Mouseover"
  237. end
  238. dragGuiState = newState
  239. setPlatformControls()
  240. if dragGuiState == "" then
  241. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = false
  242. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = false
  243. elseif dragGuiState == "Mouseover" then
  244. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = true
  245. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = false
  246. elseif dragGuiState == "Dragging" then
  247. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = false
  248. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = bodyGyro.Parent ~= nil and (not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 1)
  249. end
  250. end
  251. end
  252. function moveDrag(pos)
  253. bodyPosition.position = pos
  254. end
  255. local rotateSpeedReduce = 0.036
  256. local lastRotateTick
  257. function rotate(amount, speed)
  258. if not draggingPart then
  259. if not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2 then
  260. Humanoid.WalkSpeed = walkSpeed
  261. end
  262. return
  263. end
  264. if Humanoid.WalkSpeed > 1 then
  265. walkSpeed = Humanoid.WalkSpeed
  266. Humanoid.WalkSpeed = 0
  267. end
  268. lastRotateTick = tick()
  269. local thisRotateTick = lastRotateTick
  270. while draggingPart and 0 < amount.magnitude and lastRotateTick == thisRotateTick do
  271. rotateCFrame = CFrame.Angles(0, -amount.X * rotateSpeedReduce, 0) * CFrame.Angles(amount.Y * rotateSpeedReduce, 0, 0) * rotateCFrame
  272. wait()
  273. end
  274. if amount.magnitude == 0 and (not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2) then
  275. Humanoid.WalkSpeed = walkSpeed
  276. end
  277. end
  278. wait(1)
  279. carryAnimationTrack = Humanoid:LoadAnimation(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger:WaitForChild("CarryItem"))
  280. input = require(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.Parent:WaitForChild("Scripts"):WaitForChild("UserInput"))
  281. input.ClickBegan(click, holdDistanceChanged)
  282. input.ClickEnded(clickEnded)
  283. input.Rotate(rotate)
  284. function setPlatformControls()
  285. if input.IsGamePadEnabled() then
  286. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Gamepad.Value
  287. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.KeyLabel.Text = ""
  288. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Gamepad.Value
  289. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.KeyLabel.Text = ""
  290. else
  291. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.PC.Value
  292. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.KeyLabel.Text = "CLICK"
  293. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.PC.Value
  294. game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.KeyLabel.Text = "SHIFT + WASD"
  295. end
  296. end
  297. interactLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement