Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Disabled = true
- local player = game.Players.LocalPlayer
- local Character = player.Character or player.CharacterAdded:wait()
- local Humanoid = Character:WaitForChild("Humanoid")
- local walkSpeed = Humanoid.WalkSpeed
- local dragPart = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger:FindFirstChild("Dragger") or game.StarterGui.ItemDraggingGUI.Dragger:FindFirstChild("Dragger"):Clone()
- dragPart.Parent = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger
- player.CharacterAdded:connect(function()
- Character = player.Character
- Humanoid = Character:WaitForChild("Humanoid")
- Humanoid.Died:connect(function()
- dragPart.Parent = nil
- end)
- end)
- wait(1)
- local dragRangeMax = 10e6
- local dragRangeMin = 7
- local camera = workspace.CurrentCamera
- local mouse = player:GetMouse()
- local button1Down = false
- local dragRange = dragRangeMax
- local bodyPosition = Instance.new("BodyPosition", dragPart)
- bodyPosition.maxForce = Vector3.new(10e9,10e9,10e9)
- bodyPosition.D = 800
- local bodyGyro = Instance.new("BodyGyro", dragPart)
- bodyGyro.maxTorque = Vector3.new(1, 1, 1) * 200
- bodyGyro.P = 1200
- bodyGyro.D = 140
- local rotateCFrame = CFrame.new()
- local weld = Instance.new("Weld", dragPart)
- local interactPermission = require(game.ReplicatedStorage.Interaction.InteractionPermission)
- local clientIsDragging = game.ReplicatedStorage.Interaction.ClientIsDragging
- local carryAnimationTrack
- local draggingPart = false
- function click()
- button1Down = true
- local targetObject = input.GetMouseTarget()
- if not canDrag(targetObject) then
- return
- end
- local mouseHit = input.GetMouseHit().p
- if (mouseHit - Character.Head.Position).magnitude > dragRangeMax then
- return
- end
- initializeDrag(targetObject, mouseHit)
- rotateCFrame = CFrame.new()
- carryAnimationTrack:Play(0.1, 1, 1)
- local dragIsFailing = 0
- local dragTime = 0
- while button1Down and canDrag(targetObject) do
- local desiredPos = Character.Head.Position + (input.GetMouseHit().p - Character.Head.Position).unit * dragRange
- local dragRay = Ray.new(Character.Head.Position, desiredPos - Character.Head.Position)
- local part, pos = workspace:FindPartOnRayWithIgnoreList(dragRay, {
- Character,
- dragPart,
- targetObject.Parent
- })
- if part then
- desiredPos = pos
- end
- if (camera.CoordinateFrame.p - Character.Head.Position).magnitude > 2 then
- desiredPos = desiredPos + Vector3.new(0, 1.8, 0)
- end
- moveDrag(desiredPos)
- bodyGyro.cframe = CFrame.new(dragPart.Position, camera.CoordinateFrame.p) * rotateCFrame
- local targParent = findHighestParent(targetObject) or targetObject
- local attemptingToSurf = false
- for _, check in pairs({
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.7, -2.8, 0)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, 0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.35, -2.8, -0.6)).p, Vector3.new(0, -2, 0))
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
- State = Enum.HumanoidStateType.Climbing
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -0.8, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
- State = Enum.HumanoidStateType.Climbing
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
- State = Enum.HumanoidStateType.Climbing
- },
- {
- Ray = Ray.new((Character.HumanoidRootPart.CFrame * CFrame.new(-0.5, -1.3, 0)).p, Character.HumanoidRootPart.CFrame.lookVector),
- State = Enum.HumanoidStateType.Climbing
- }
- }) do
- local ray = check.Ray
- local part, _ = workspace:FindPartOnRayWithIgnoreList(ray, {Character})
- local op = part
- part = part and findHighestParent(part)
- if part and (not check.State or Humanoid:GetState() == check.State) then
- if part == targParent then
- attemptingToSurf = true
- else
- for _, connectedPart in pairs(op:GetConnectedParts(true)) do
- if connectedPart == targetObject then
- attemptingToSurf = true
- break
- end
- end
- end
- end
- end
- local falling = Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.FallingDown
- dragIsFailing = 0
- if dragTime % 10 == 0 and targParent.Parent:FindFirstChild("BedInfo") and targParent.Parent:FindFirstChild("Main") then
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.Parent.Scripts.VehicleControl.SetVehicleOwnership:Fire(targParent.Parent.Main)
- end
- clientIsDragging:FireServer(targParent.Parent)
- wait()
- dragTime = dragTime + 1
- end
- carryAnimationTrack:Stop()
- endDrag()
- end
- function findHighestParent(child)
- if not (child and child.Parent) or child.Parent == workspace then
- return nil
- end
- local ret = child.Parent:FindFirstChild("Owner") and child
- return findHighestParent(child.Parent) or ret
- end
- function clickEnded()
- button1Down = false
- end
- function holdDistanceChanged(dist)
- dragRange = dragRangeMin + (1 - dist) * (dragRangeMax - dragRangeMin)
- end
- function canDrag(targetObject)
- for _, instance in pairs(Character:GetChildren()) do
- if instance:IsA("Tool") then
- return false
- end
- end
- if not (targetObject and not targetObject.Anchored and targetObject.Parent) or not (Humanoid.Health > 0) then
- return false
- end
- if targetObject.Name == "LeafPart" then
- return false
- end
- local originTargetObject = targetObject
- targetObject = findHighestParent(targetObject) or targetObject
- if game.Players:GetPlayerFromCharacter(targetObject.Parent.Parent) then
- return false
- end
- bodyGyro.Parent = dragPart
- if not targetObject.Parent:FindFirstChild("Owner") then
- return otherDraggable(targetObject, originTargetObject)
- end
- if not interactPermission:UserCanInteract(player, targetObject.Parent) then
- return false
- end
- if targetObject.Parent:FindFirstChild("TreeClass") then
- return true
- end
- if targetObject.Parent:FindFirstChild("BoxItemName") then
- return true
- end
- if targetObject.Parent:FindFirstChild("PurchasedBoxItemName") then
- return true
- end
- if targetObject.Parent:FindFirstChild("Handle") then
- return true
- end
- return otherDraggable(targetObject, originTargetObject)
- end
- function otherDraggable(targetObject, originTargetObject)
- local draggable = targetObject and targetObject.Parent and targetObject.Parent:FindFirstChild("DraggableItem") or originTargetObject and originTargetObject.Parent and originTargetObject.Parent:FindFirstChild("DraggableItem")
- if draggable then
- if draggable:FindFirstChild("NoRotate") then
- bodyGyro.Parent = nil
- end
- return true
- end
- end
- function initializeDrag(targetObject, mouseHit)
- draggingPart = true
- mouse.TargetFilter = targetObject and findHighestParent(targetObject) and findHighestParent(targetObject).Parent or targetObject
- dragPart.CFrame = CFrame.new(mouseHit, camera.CoordinateFrame.p)
- weld.Part0 = dragPart
- weld.Part1 = targetObject
- weld.C0 = CFrame.new(mouseHit, camera.CoordinateFrame.p):inverse() * targetObject.CFrame
- weld.Parent = dragPart
- dragPart.Parent = workspace
- end
- function endDrag()
- mouse.TargetFilter = nil
- dragPart.Parent = nil
- draggingPart = false
- end
- local dragGuiState = ""
- function interactLoop()
- while true do
- wait()
- local newState = ""
- local mouseHit = input.GetMouseHit().p
- local targetObject = input.GetMouseTarget()
- if draggingPart then
- newState = "Dragging"
- elseif canDrag(targetObject) and not button1Down and (mouseHit - Character.Head.Position).magnitude < dragRangeMax then
- newState = "Mouseover"
- end
- dragGuiState = newState
- setPlatformControls()
- if dragGuiState == "" then
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = false
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = false
- elseif dragGuiState == "Mouseover" then
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = true
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = false
- elseif dragGuiState == "Dragging" then
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.Visible = false
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.Visible = bodyGyro.Parent ~= nil and (not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 1)
- end
- end
- end
- function moveDrag(pos)
- bodyPosition.position = pos
- end
- local rotateSpeedReduce = 0.036
- local lastRotateTick
- function rotate(amount, speed)
- if not draggingPart then
- if not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2 then
- Humanoid.WalkSpeed = walkSpeed
- end
- return
- end
- if Humanoid.WalkSpeed > 1 then
- walkSpeed = Humanoid.WalkSpeed
- Humanoid.WalkSpeed = 0
- end
- lastRotateTick = tick()
- local thisRotateTick = lastRotateTick
- while draggingPart and 0 < amount.magnitude and lastRotateTick == thisRotateTick do
- rotateCFrame = CFrame.Angles(0, -amount.X * rotateSpeedReduce, 0) * CFrame.Angles(amount.Y * rotateSpeedReduce, 0, 0) * rotateCFrame
- wait()
- end
- if amount.magnitude == 0 and (not player:FindFirstChild("IsChatting") or player.IsChatting.Value < 2) then
- Humanoid.WalkSpeed = walkSpeed
- end
- end
- wait(1)
- carryAnimationTrack = Humanoid:LoadAnimation(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger:WaitForChild("CarryItem"))
- input = require(game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.Parent:WaitForChild("Scripts"):WaitForChild("UserInput"))
- input.ClickBegan(click, holdDistanceChanged)
- input.ClickEnded(clickEnded)
- input.Rotate(rotate)
- function setPlatformControls()
- if input.IsGamePadEnabled() then
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Gamepad.Value
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.KeyLabel.Text = ""
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Gamepad.Value
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.KeyLabel.Text = ""
- else
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.PC.Value
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanDrag.PlatformButton.KeyLabel.Text = "CLICK"
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.Image = game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.PC.Value
- game.Players.LocalPlayer.PlayerGui.ItemDraggingGUI.Dragger.Parent.CanRotate.PlatformButton.KeyLabel.Text = "SHIFT + WASD"
- end
- end
- interactLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement