How do i make the character look where the gun aims?

i want to make the character look where i aim, like in arsenal.
i tried this script but it makes me rotate in weird ways and its just not really working.

local function OnMouseMove()
	if not Equipped then return end

	local humanoid = char:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		local mousePosition = mouse.Hit.Position
		local HandleCFrame = script.Parent.Handle.CFrame
		local ShotCFrame = CFrame.new(HandleCFrame.Position, mousePosition)
		
		char.UpperTorso.Waist.C0 = CFrame.new(char.UpperTorso.Waist.C0.Position) * ShotCFrame.Rotation
	end
end

1 Like

You can try to if you mean to look at mouse then do this

Local in start character scripts:

local CFnew, CFang = CFrame.new, CFrame.Angles
local asin = math.asin
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()

script.Parent:WaitForChild("Torso")

local Torso = script.Parent:WaitForChild("Torso")
local Head = script.Parent:WaitForChild("Head")

local Motors = {}

table.insert(Motors,Torso:WaitForChild("Left Shoulder"))
table.insert(Motors,Torso:WaitForChild("Right Shoulder"))
table.insert(Motors,Torso:WaitForChild("Neck"))

local function UpdateAll()

	if game.Players.LocalPlayer.Name == script.Parent.Name then

		local function UpdateMotor6D(v,c)
			local Target = c
			script.RemoteEvent:FireServer(c,v)
		end

		local CameraCalculation = (-asin((Mouse.Origin.Position - Mouse.Hit.Position).unit.y))
		
		
		--// Head
		
		local Motor = Torso:WaitForChild("Neck")
		local cframe = CFnew(0,1,0) * CFang(CameraCalculation-math.rad(90), math.rad(Motor.C0.Rotation.Y), math.rad(-180))
		UpdateMotor6D(Motor,cframe)
		Motor.C0 = cframe
		
		
		if script.On.Value == false then
			CameraCalculation = 0
		end
		
		
		--// Arms
		
		local Motor = Torso:WaitForChild("Left Shoulder")
		local cframe = CFnew(-1, .5, 0) * CFang(CameraCalculation, -1.55, Motor.C0.Rotation.Z)
		UpdateMotor6D(Motor,cframe)
		Motor.C0 = cframe

		local Motor = Torso:WaitForChild("Right Shoulder")
		local cframe = CFnew(1, .5, 0) * CFang(CameraCalculation, 1.55, Motor.C0.Rotation.Z)
		UpdateMotor6D(Motor,cframe)
		Motor.C0 = cframe

	end
end

game:GetService("RunService").RenderStepped:Connect(function()
	--wait(0.01)
	UpdateAll()
end)

and then, insert these:

image

Make sure script in startercahracter

And then, in the server script:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,cfrrr,weld)
	--local t = game.TweenService:Create(weld,TweenInfo.new(.3,Enum.EasingStyle.Exponential),{C0 = cfrrr})
	--t:Play()
	weld.C0 = cfrrr
end)

Now, the character head and arms should face to mouse. You can edit the “on” value to make it only do head and not arms depending on the value.

The client script allows the client to see smooth moving arms, but on the server to other players it may not look as good but that shouldn’t be a huge problem.

2 Likes

its a r15 game. do i just replace everywhere where it says torso to “UpperTorso”?

You would have to then replace “Left Shoulder” with the R15 rig most upper arm motor6d.
Same with Right Shoulder.

And yes for the torso, change it to find the Upper Torso. (Or the torso that holds the motors.

there is not one torso that holds all motors. i see that every part in the character has one motor

I have no idea how r15 works but it is always going to be very complex for things like this

this is why I use R6