Trouble pointing hands with motor6d

  1. What do you want to achieve?
    A grab/drag system that points the players arms (R6 rig by the way) toward the GrabAttachment on the object

  2. What is the issue?
    The hands dont do anything, i did try to make them point using motor6d but they were getting affected by the walking animatiton. I have also tried using .transform but i dont really know how to use it.

  3. What solutions have you tried so far?
    Ive tried disabling the animations while grabbing, but it creates a weird effect which im not looking for. Ive also tried to remake most of the script (other versions) but it didnt work out.

Below is the current script

local Players = game:GetService("Players")
local Myself = Players.LocalPlayer
local MyMouse = Myself:GetMouse()
local MyCharacter = script.Parent
local MyCamera = workspace.CurrentCamera

local UserInput = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage")

local KeyboardBindings = { E = "Grab" }
local BindingTypes = { Keyboard = KeyboardBindings }

local RayParams = RaycastParams.new()
RayParams.RespectCanCollide = true
RayParams.FilterDescendantsInstances = { MyCharacter }

local GrabOrientation = script.AlignOrientation
local GrabPosition = script.AlignPosition
GrabPosition.MaxForce = 3000
GrabPosition.Responsiveness = 20

local GrabAttachment
local GrabDetails = {}
local Holding = false
local FixedDistance = 7
local Smoothness = 0.2

local RShoulderOffset = CFrame.new(1.5, 0.75, -1)
local LShoulderOffset = CFrame.new(-1.5, 0.75, -1)

local torso = MyCharacter:FindFirstChild("Torso") or MyCharacter:FindFirstChild("UpperTorso")
local rShoulder, lShoulder
local origRShouldC0, origLShouldC0 

if torso then
	rShoulder = torso:FindFirstChild("Right Shoulder")
	lShoulder = torso:FindFirstChild("Left Shoulder")
	if rShoulder then origRShouldC0 = rShoulder.C0 end
	if lShoulder then origLShouldC0 = lShoulder.C0 end
end

local Checker = require(Storage.Modules.GrabbableChecker)

local function Drop()
	GrabDetails.Part = nil
	GrabDetails.Distance = nil
	GrabPosition.Attachment0 = nil
	GrabOrientation.Attachment0 = nil

	if GrabAttachment then
		GrabAttachment:Destroy()
		GrabAttachment = nil
	end

	if rShoulder then rShoulder.Transform = CFrame.identity end
	if lShoulder then lShoulder.Transform = CFrame.identity end

	Holding = false
	Storage.Events.Release:FireServer()
end

local function TryGrab()
	local ray = workspace:Raycast(MyMouse.UnitRay.Origin, MyMouse.UnitRay.Direction * FixedDistance, RayParams)
	if not ray then return end

	local target = ray.Instance
	if not pcall(function() Checker.Check(target) end) or not Checker.Grabbable then return end

	GrabDetails.Part = target
	GrabDetails.Distance = ray.Distance
	local offset = target:GetAttribute("GrabOffset")
	GrabDetails.Orientation = offset or MyCamera.CFrame:ToObjectSpace(target.CFrame)

	GrabAttachment = Instance.new("Attachment")
	GrabAttachment.Parent = target
	GrabAttachment.WorldPosition = ray.Position

	GrabPosition.Attachment0 = GrabAttachment
	GrabOrientation.Attachment0 = GrabAttachment
	GrabAttachment.Destroying:Connect(Drop)

	Storage.Events.Grab:FireServer(target)
	Holding = true
end

UserInput.InputBegan:Connect(function(input, inGUI)
	if inGUI then return end
	local binds = BindingTypes[input.UserInputType.Name] or BindingTypes.Keyboard
	if binds[input.KeyCode.Name] == "Grab" then
		if Holding then Drop() else TryGrab() end
	end
end)

RunService.Heartbeat:Connect(function()
	if not GrabDetails.Part then return end

	local root = MyCharacter:FindFirstChild("HumanoidRootPart")
	if not root then return end

	local mousePos = Vector2.new(MyMouse.X, MyMouse.Y)
	local camRay = MyCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
	local dir = camRay.Direction.Unit

	local goalPos = root.Position + dir * (FixedDistance - 0.3)
	GrabPosition.Position = GrabPosition.Position:Lerp(goalPos, math.clamp(Smoothness, 0, 1))

	local curO = GrabOrientation.CFrame
	local tgtO = MyCamera.CFrame:ToWorldSpace(GrabDetails.Orientation)
	GrabOrientation.CFrame = curO:Lerp(tgtO, math.clamp(Smoothness, 0, 1))

	if (GrabDetails.Part.Position - root.Position).Magnitude > FixedDistance * 2 then
		Drop()
	end

	if Holding and GrabAttachment and torso then
		local targetPos = GrabAttachment.WorldPosition

		if rShoulder and origRShouldC0 then
			local shoulderWorld = torso.CFrame * RShoulderOffset
			local lookCFrame = CFrame.lookAt(shoulderWorld.Position, targetPos, torso.CFrame.UpVector)
			local adjusted = lookCFrame * CFrame.Angles(math.rad(90), 0, 0)
			rShoulder.Transform = origRShouldC0:Inverse() * torso.CFrame:ToObjectSpace(adjusted)
		end

		if lShoulder and origLShouldC0 then
			local shoulderWorld = torso.CFrame * LShoulderOffset
			local lookCFrame = CFrame.lookAt(shoulderWorld.Position, targetPos, torso.CFrame.UpVector)
			local adjusted = lookCFrame * CFrame.Angles(math.rad(-90), 0, 0)
			lShoulder.Transform = origLShouldC0:Inverse() * torso.CFrame:ToObjectSpace(adjusted)
		end
	end
end)

Below is the script that disabled animations while grabbing

local Players = game:GetService("Players")
local Myself = Players.LocalPlayer
local MyMouse = Myself:GetMouse()
local MyCharacter = script.Parent
local MyCamera = workspace.CurrentCamera

local UserInput = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage")

local KeyboardBindings = { E = "Grab" }
local BindingTypes = { Keyboard = KeyboardBindings }

local RayParams = RaycastParams.new()
RayParams.RespectCanCollide = true
RayParams.FilterDescendantsInstances = { MyCharacter }

local GrabOrientation = script.AlignOrientation
local GrabPosition = script.AlignPosition
local GrabAttachment
local GrabDetails = {}
local Holding = false
local FixedDistance = 7
local Smoothness = 0.2

local RShoulderOffset = CFrame.new(1.5, 0.75, -1)
local LShoulderOffset = CFrame.new(-1.5, 0.75, -1)

local torso = MyCharacter:FindFirstChild("Torso") or MyCharacter:FindFirstChild("UpperTorso")
local rShoulder, lShoulder
local origRShouldC0, origLShouldC0

if torso then
	rShoulder = torso:FindFirstChild("Right Shoulder")
	lShoulder = torso:FindFirstChild("Left Shoulder")
	if rShoulder then origRShouldC0 = rShoulder.C0 end
	if lShoulder then origLShouldC0 = lShoulder.C0 end
end

local Checker = require(Storage.Modules.GrabbableChecker)

local function Drop()
	GrabDetails.Part = nil
	GrabDetails.Distance = nil
	GrabPosition.Attachment0 = nil
	GrabOrientation.Attachment0 = nil

	if GrabAttachment then
		GrabAttachment:Destroy()
		GrabAttachment = nil
	end

	if rShoulder and origRShouldC0 then rShoulder.C0 = origRShouldC0 end
	if lShoulder and origLShouldC0 then lShoulder.C0 = origLShouldC0 end

	local humanoid = MyCharacter:FindFirstChild("Humanoid")
	if humanoid and not humanoid:FindFirstChildOfClass("Animator") then
		Instance.new("Animator", humanoid)
	end

	Holding = false
	Storage.Events.Release:FireServer()
end

local function TryGrab()
	local ray = workspace:Raycast(MyMouse.UnitRay.Origin, MyMouse.UnitRay.Direction * FixedDistance, RayParams)
	if not ray then return end

	local target = ray.Instance
	if not pcall(function() Checker.Check(target) end) or not Checker.Grabbable then return end

	GrabDetails.Part = target
	GrabDetails.Distance = ray.Distance
	local offset = target:GetAttribute("GrabOffset")
	GrabDetails.Orientation = offset or MyCamera.CFrame:ToObjectSpace(target.CFrame)

	GrabAttachment = Instance.new("Attachment")
	GrabAttachment.Parent = target
	GrabAttachment.WorldPosition = ray.Position

	GrabPosition.Attachment0 = GrabAttachment
	GrabOrientation.Attachment0 = GrabAttachment
	GrabAttachment.Destroying:Connect(Drop)

	Storage.Events.Grab:FireServer(target)
	Holding = true

	local humanoid = MyCharacter:FindFirstChild("Humanoid")
	if humanoid then
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then animator:Destroy() end
	end
end

UserInput.InputBegan:Connect(function(input, inGUI)
	if inGUI then return end
	local binds = BindingTypes[input.UserInputType.Name] or BindingTypes.Keyboard
	if binds[input.KeyCode.Name] == "Grab" then
		if Holding then Drop() else TryGrab() end
	end
end)

RunService.Heartbeat:Connect(function()
	if not GrabDetails.Part then return end

	local root = MyCharacter:FindFirstChild("HumanoidRootPart")
	if not root then return end

	local mousePos = Vector2.new(MyMouse.X, MyMouse.Y)
	local camRay = MyCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
	local dir = camRay.Direction.Unit
	local goalPos = root.Position + dir * FixedDistance

	GrabPosition.Position = GrabPosition.Position:Lerp(goalPos, math.clamp(Smoothness, 0, 1))

	local curO = GrabOrientation.CFrame
	local tgtO = MyCamera.CFrame:ToWorldSpace(GrabDetails.Orientation)
	GrabOrientation.CFrame = curO:Lerp(tgtO, math.clamp(Smoothness, 0, 1))

	if (GrabDetails.Part.Position - root.Position).Magnitude > FixedDistance * 2 then Drop() end

	if Holding and GrabAttachment and torso then
		local targetPos = GrabAttachment.WorldPosition
		local upVec = torso.CFrame.UpVector

		if rShoulder then
			local shoulderWorld = torso.CFrame * RShoulderOffset
			local lookCFrame = CFrame.lookAt(shoulderWorld.Position, targetPos, upVec)
			local adjusted = lookCFrame * CFrame.Angles(math.rad(90), 0, 0)
			rShoulder.C0 = torso.CFrame:ToObjectSpace(adjusted)
		end

		if lShoulder then
			local shoulderWorld = torso.CFrame * LShoulderOffset
			local lookCFrame = CFrame.lookAt(shoulderWorld.Position, targetPos, upVec)
			local adjusted = lookCFrame * CFrame.Angles(math.rad(90), 0, 0)
			lShoulder.C0 = torso.CFrame:ToObjectSpace(adjusted)
		end
	end
end)

I also have one that kinda works, but the hands only move up and down

(someone helped me out on this version)

Script here
local Players = game:GetService("Players")
local Myself = Players.LocalPlayer
local MyMouse = Myself:GetMouse()
local MyCharacter = script.Parent
local MyCamera = workspace.CurrentCamera

local UserInput = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage")

local KeyboardBindings = { E = "Grab" }
local BindingTypes = { Keyboard = KeyboardBindings }

local RayParams = RaycastParams.new()
RayParams.RespectCanCollide = true
RayParams.FilterDescendantsInstances = { MyCharacter }

local GrabOrientation = script.AlignOrientation
local GrabPosition = script.AlignPosition
GrabPosition.MaxForce = 3000
GrabPosition.Responsiveness = 20
local GrabAttachment
local GrabDetails = {}
local Holding = false

local MaxGrabRange  = 8
local HoldDistance  = 5

local Smoothness = 0.2

local RShoulderOffset = CFrame.new(1.5, 0.75, -1)
local LShoulderOffset = CFrame.new(-1.5, 0.75, -1)

local torso = MyCharacter:FindFirstChild("Torso") or MyCharacter:FindFirstChild("UpperTorso")
local rShoulder, lShoulder
local origRShouldC0, origLShouldC0

if torso then
	rShoulder = torso:FindFirstChild("Right Shoulder")
	lShoulder = torso:FindFirstChild("Left Shoulder")
	if rShoulder then origRShouldC0 = rShoulder.C0 end
	if lShoulder then origLShouldC0 = lShoulder.C0 end
end

local Checker = require(Storage.Modules.GrabbableChecker)

local function Drop()
	GrabDetails.Part = nil
	GrabDetails.Distance = nil
	GrabPosition.Attachment0 = nil
	GrabOrientation.Attachment0 = nil

	if GrabAttachment then
		GrabAttachment:Destroy()
		GrabAttachment = nil
	end

	if rShoulder and origRShouldC0 then rShoulder.C0 = origRShouldC0 end
	if lShoulder and origLShouldC0 then lShoulder.C0 = origLShouldC0 end

	Holding = false
	Storage.Events.Release:FireServer()
end

local function TryGrab()
	local ray = workspace:Raycast(
		MyMouse.UnitRay.Origin,
		MyMouse.UnitRay.Direction * MaxGrabRange,
		RayParams
	)
	if not ray then return end

	local target = ray.Instance
	if not pcall(function() Checker.Check(target) end) or not Checker.Grabbable then return end

	GrabDetails.Part = target
	GrabDetails.Distance = ray.Distance
	local offset = target:GetAttribute("GrabOffset")
	GrabDetails.Orientation = offset or MyCamera.CFrame:ToObjectSpace(target.CFrame)

	GrabAttachment = Instance.new("Attachment")
	GrabAttachment.Parent = target
	GrabAttachment.WorldPosition = ray.Position

	GrabPosition.Attachment0 = GrabAttachment
	GrabOrientation.Attachment0 = GrabAttachment
	GrabAttachment.Destroying:Connect(Drop)

	Storage.Events.Grab:FireServer(target)
	Holding = true
	game.SoundService.pickup:Play()
end

UserInput.InputBegan:Connect(function(input, inGUI)
	if inGUI then return end
	local binds = BindingTypes[input.UserInputType.Name] or BindingTypes.Keyboard
	if binds[input.KeyCode.Name] == "Grab" then
		if Holding then Drop() else TryGrab() end
	end
end)

RunService.Heartbeat:Connect(function()
	if not GrabDetails.Part then return end

	local root = MyCharacter:FindFirstChild("HumanoidRootPart")
	if not root then return end

	local mousePos = Vector2.new(MyMouse.X, MyMouse.Y)
	local camRay = MyCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
	local dir = camRay.Direction.Unit
	local buffer = 0.3
	local goalPos = root.Position + dir * (HoldDistance - buffer)
	GrabPosition.Position = GrabPosition.Position:Lerp(goalPos, math.clamp(Smoothness, 0, 1))

	local curO = GrabOrientation.CFrame
	local tgtO = MyCamera.CFrame:ToWorldSpace(GrabDetails.Orientation)
	GrabOrientation.CFrame = curO:Lerp(tgtO, math.clamp(Smoothness, 0, 1))

	if (GrabDetails.Part.Position - root.Position).Magnitude > HoldDistance * 2 then
		Drop()
	end

	if Holding and GrabAttachment and torso then
		local targetPos = GrabAttachment.WorldPosition
		local upVec = torso.CFrame.UpVector

		if rShoulder then
			local baseC0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.rad(90), 0)
			local lookCF = CFrame.lookAt((torso.CFrame * baseC0).Position, targetPos, upVec)
			local ox, oy, oz = lookCF:ToOrientation()
			rShoulder.C0 = baseC0 * rShoulder.Transform:Inverse() * CFrame.Angles(0, 0, ox + math.rad(90))
		end

		if lShoulder then
			local baseC0 = CFrame.new(-2, 0.5, 0) * CFrame.Angles(0, math.rad(90), 0)
			local lookCF = CFrame.lookAt((torso.CFrame * baseC0).Position, targetPos, upVec)
			local ox, oy, oz = lookCF:ToOrientation()

			lShoulder.C0 = baseC0 * lShoulder.Transform:Inverse() * CFrame.Angles(0, 0, ox + math.rad(90))
		end
	end
end)

Basically, i cant get it to work even with 3 versions that do separate things…

You can use IK Controls (Inverse Kinematics)
It uses math to point to things

local rightIK = Instance.new("IKControl")
rightIK.Name = "RightArmGrabIK"
rightIK.Type = Enum.IKControlType.Position
rightIK.ChainRoot = MyCharacter:WaitForChild("Right Shoulder")
rightIK.EndEffector = MyCharacter:WaitForChild("Right Arm")
rightIK.Target = GrabAttachment
rightIK.Parent = MyCharacter
1 Like

Im using an r6 rig so i cant use IK