Make character's arm point toward mouse regardless of character rotation

I’ve never been that well with CFrames and need a little help.
I’m trying to make the player’s right arm point toward the mouse, but when the character turns around 180 degrees, it appears to function as if the character wasn’t rotated 180 degrees.

IT’s something to do with world and object space, but I’m unsure of how to resolve this issue.


When the player rotates is the problem, as it is pointing behind not in front. It’s not taking the current rotation of the character into consideration. How can I make it work for all rotations of my character?

Current code:

local Players = game:GetService(“Players”)

local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()

local armOffset = char.UpperTorso.CFrame:Inverse() * char.RightUpperArm.CFrame

local armWeld = Instance.new(“Weld”)
armWeld.Part0 = char.UpperTorso
armWeld.Part1 = char.RightUpperArm
armWeld.Parent = char

mouse.Move:Connect(function()
local x,y,z = CFrame.new(char.RightUpperArm.Position,mouse.Hit.Position):ToEulerAnglesXYZ()
armWeld.C0 = armOffset * CFrame.fromEulerAnglesXYZ(x,y,z) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
end)

14 Likes

I tinkered with your code a bit and managed to get it working. Here is what I did:

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()

local armOffset = char.UpperTorso.CFrame:Inverse() * char.RightUpperArm.CFrame

local armWeld = Instance.new("Weld")
armWeld.Part0 = char.UpperTorso
armWeld.Part1 = char.RightUpperArm
armWeld.Parent = char

RunService.Heartbeat:Connect(function()
	local cframe = CFrame.new(char.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
	armWeld.C0 = armOffset * char.UpperTorso.CFrame:toObjectSpace(cframe)
end)
42 Likes

what script is it and where do you put it? @systemac

1 Like

script type : Local Script
put it at StarterCharacterScripts in StarterPlayer
@GamingExpert0312

1 Like

thanks helped with my game im trying to make roblox with very cool controls

2 Likes

Well I made it for R6 as well

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local char = Player.Character or Player.CharacterAdded:Wait()
local Root = char:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local CN,CA = CFrame.new,CFrame.Angles
local an = math.asin

local armOffset = char.Torso.CFrame:Inverse() * char["Right Arm"].CFrame


local armWeld = Instance.new("Weld")
armWeld.Part0 = char.Torso
armWeld.Part1 = char["Right Arm"]
armWeld.Parent = char

RunService.Heartbeat:Connect(function()
	local cframe = CN(char.Torso.Position, Mouse.Hit.Position) * CA(math.pi/2, 0, 0)
	armWeld.C0 = armOffset * char.Torso.CFrame:toObjectSpace(cframe) * CN(0,0,-0.5)
end)
13 Likes

how can i make it replicate to the server? i tried but the arm is teleporting

1 Like

now thats a trillion dollar question that I dunno

Hello, Do you have a way so you can put a tool in that hand.

1 Like

Using tweenservice, you can tween your arm to the “mouse position” while being constantly updated via remoteEvent and you can use magnitude so that way it doesn’t always render or run for other players while out of a certain distance.

try to look up with this script lol, it’s kinda broken.

(i mean look up in 1st person)

yea thats just how roblox does.

use remote event. Send the arm.C0 to server so the server can set that to the arm on server