Using mouse.hit, I attempted to make a player's arm always point to the mouse. This is my result.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Active = false script.Parent.Equipped:connect(function() Active = true repeat Player.Character.Torso["Right Shoulder"].C0 = CFrame.new(Player.Character.Torso["Right Shoulder"].C0.p, Mouse.Hit.p) game:GetService("RunService").RenderStepped:wait() until Active == false end)
Now, the issue with this is that it doesn't point towards the mouse. I have tried other methods, such as getting the components, but so far nothing has worked the way I want it to. Any ideas as to why?
You seem to be going about it incorrectly. Make a CFrame that starts at the shoulder, looking at the mouse (in world coordinates). Then, "subtract" it by the shoulder's CFrame in world coordinates. Afterwards, rotate it so it points at the right direction. Lastly, offset it by half an arm's length forward (y-axis).
repeat -- the shoulder's CFrame, in world coords (??). local shoulder = Player.Character.Torso.CFrame * CFrame.new(1, 0.5, 0) -- the CFrame where the mouse hit local lookat = Mouse.Hit -- creates a cframe starting at the shoulder, looking at where the mouse hit local newC0 = CFrame.new(shoulder.p, lookat.p) -- multiplies the cframe by the inverse of the shoulder's cframe. newC0 = Player.Character.Torso.CFrame:inverse() * newC0 -- rotates the arm so that it points in the right direction newC0 = newC0 * CFrame.Angles(math.pi/2, 0, -math.pi/2) -- moves it by one stud towards where the arm is pointing newC0 = newC0 * CFrame.new(1, 0, 0) -- sets the shoulder's CFrame Player.Character.Torso["Right Shoulder"].C0 = newC0 game:GetService("RunService").RenderStepped:wait() until Active == false
By the way, I would recommend binding this to RenderStepped instead of using RenderStepped:wait()