I’m working on a “custom tool” and I want it to follow the mouse cursor.
It still uses the Roblox Tool but I do not use the ToolGrip Weld, instead I use a Motor6D.
In my tool, there’s a part that holds all the other parts, named BodyAttach. It holds other part by using Motor6Ds.
When player equips a tool, a torso Motor6D will connect between character’s Torso and BodyAttach.
Here’s the script that makes it follow the mouse:
game:GetService("RunService").RenderStepped:Connect(function()
if char.Humanoid.Health ~= 0 then
if char:FindFirstChildOfClass("Tool") then
char.Torso["Right Shoulder"].C0 = CFrame.new(1,0.5,0) * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),1.55,0)
char.Torso["Left Shoulder"].C0 = CFrame.new(-1,0.5,0) * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),-1.55,0)
char.Torso:WaitForChild("ToolGrip").C0 = CFrame.new(0,0,0) * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),0,0)
else
char.Torso["Right Shoulder"].C0 = RS
char.Torso["Left Shoulder"].C0 = LS
end
end
end)
However this makes the tool goes off the arm when it was being pointed too high (Notice the shooting handle and the Right Arm), is there any ways to improve the code or anything wrong such that this doesn’t happen?
This is an expected behavior (From the game Reason 2 Die)