Hello fellow developers,
I just thought of a way to rotate the player arm’s Y position according to the mouse’s Y position. After some research I came up with this script:
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local char = script.Parent
local torso = char:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local function updateArmRotation()
local angle = math.rad((mouse.UnitRay.Direction.Y * 100) / 2)
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.rad(90), angle)
end
game:GetService("RunService").RenderStepped:Connect(updateArmRotation)
It uses mouse.UnitRay (which I myself dont really know how it works), takes the Y position of the direction of the ray, multiplies it with 100 and then divides it by 2. math.rad() is used for CFrame.Angles(). After that it takes the initial position of the shoulder motor and multiplies it with CFrame.Angles() to get the rotation. The function is connected to RunService.RenderStepped to update the rotation of the arm every frame.
This is a LocalScript, put into StarterCharacterScripts.