What solutions have you tried so far? I have searched the developer hub, and have just messed around with this for the past couple days.
This is a localscript, placed inside StarterCharacterScripts.
local Character = script.Parent
Character:WaitForChild("Right Arm").PivotOffset = CFrame.new(0, 0.5, 0)
while true do wait()
Character:WaitForChild("Right Arm").Orientation = Vector3.new(Character:WaitForChild("Right Arm").Orientation.X, (game:GetService("Players").LocalPlayer:GetMouse().Y/game:GetService("Workspace").CurrentCamera.ViewportSize.Y), Character:WaitForChild("Right Arm").Orientation.Z)
print(Character:WaitForChild("Right Arm").Orientation)
end
lol, well I have created a sample script, which you can move your mouse up and down with, and in order for it to run, it needs to be executed in a client script.
here is the sample script:
local Player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tors = character:WaitForChild("Torso")
local rightshoulder = tors:WaitForChild("Right Shoulder")
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
local X = -(math.asin((mouse.Origin.p - mouse.Hit.p).unit.y))
local _, Y, Z = rightshoulder.C0:ToEulerAnglesXYZ()
rightshoulder.C0 = CFrame.new(rightshoulder.C0.Position) * CFrame.Angles(X-50, math.rad(90),0)
end)
Instead of trying to use the position of the character, I would recommend using the CFrame instead, if you are trying to get an accurate angle. There really isn’t a need to use a loop for this, as it might crash or lag the game, or act up, like it did for you.
~~ Make sure the code is in a client script, and inside of StarterPlayer or StarterPlayerScripts. ~~
@mysticalsunshine22 Thank you so much! I have no idea what most of this means, but I made it work.
Here is the code for anyone looking for answers in this post.
local Player = game:GetService("Players").LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local tors = character:WaitForChild("Torso")
local rightshoulder = tors:WaitForChild("Right Shoulder")
local RunService = game:GetService("RunService")
local Mouse = Player:GetMouse()
RunService.RenderStepped:Connect(function()
local X = -(math.asin((Mouse.Origin.p - Mouse.Hit.p).unit.y))
local _, Y, Z = rightshoulder.C0:ToEulerAnglesXYZ()
rightshoulder.C0 = CFrame.new(rightshoulder.C0.Position) * CFrame.Angles((X+180)*2, math.rad(90),0)
end)