Trouble rotating character's arm

I’m very sorry if I am doing something horribly wrong, but I’ve been stumped over the past few days over this allegedly simple piece of code.

  1. What do you want to achieve? I would like the player’s arm to rotate up and down based on the Y position of the player’s mouse to move a flashlight.

  2. What is the issue? Instead of moving simply up and down, my character’s arm is jiggling around like jello.

  3. 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

if you want to move the chracter’s arm you should probably use .Position istead of .Orientation

1 Like

Sorry I didn’t clarify, but when I said up and down, I meant to rotate like that. I will edit the post.

try this :

Character:WaitForChild("Right Arm").Orientation = Vector3.new((game:GetService("Players").LocalPlayer:GetMouse().Y/game:GetService("Workspace").CurrentCamera.ViewportSize.Y),Character:WaitForChild("Right Arm").Orientation.Y , Character:WaitForChild("Right Arm").Orientation.Z)

You rotated the wrong axis

It is still behaving like jello, should I just use Motor6D?

Maybe try using CFrame to rotate the hand, may I see the full script?

1 Like

Ngl that was the full script lol

1 Like

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. ~~

Here is the source I used:

1 Like

@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)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.