Need help with torso and head following mouse

So does this only work for one player at a time? Because there are only one set of variables.

i made a thing for this but its r6 only
just try using my EZ convert then reference
here
local Client=require(7773229488)–[[please note i used a bit of code from Nebulas EZ convert just so you know and all the rest is mine :)]]
Mouse=Client.MouseInfo
localPlayer=game:GetService(“Players”).LocalPlayer
while wait(1) do
print(localPlayer:GetMouse().Hit)
end

thats an easy way for a getmouse method
also if the EZ convert stops working there are a few possible reasons:
its a pre update test before i upload the version as officially tested and is bugged/privated/etc
or roblox update caused it to stop working

1 Like

also i forgot to mention that you gotta do Client:Start() to start the client to server conversation

i got the script ready

local Replicator=require(7773229488)
Replicator:Start()
local Mouse=game:GetService("Players").LocalPlayer:GetMouse()
while wait(1) do
	warn(Mouse.Hit)
end
2 Likes

This script work for R6 character?

lol did you read his entire post?

it won’t work for me so i just make sure

I have not worked on that module in awhile so it may not work because I think I broke something inside the converter trying to achieve something but I am not really sure because its been a few months since i worked on it…
I may have accidentally bugged it but I cannot remember so idrk ill check sometime soon and if I did ill fix it…

1 Like

i fixed it in a new require:

local Replicator=require(8465093005)
Replicator:Start()
local Mouse=game:GetService("Players").LocalPlayer:GetMouse()
while wait(1) do
	warn(Mouse.Hit)
end

if it breaks again let me know i will try to help if im not in school or doing other stuff…
and i will start working on it again to finish it…

ALSO another thing it will fix LoadLibrary automatically…
im done here.

I isolated the ‘follow mouse’ scripts from the following game’s pistol tool, they are compatible with both R6 and R15 avatar types.

https://www.roblox.com/games/203885589/Combat

--LOCAL

local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character	
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")
local torso, rightArm, neck, rightShoulder
if humanoid.RigType == Enum.HumanoidRigType.R6 then
	torso = character:WaitForChild("Torso")
	rightArm = character:WaitForChild("Right Arm")
	neck = torso:WaitForChild("Neck")
	rightShoulder = rightArm:WaitForChild("Right Shoulder")
elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
	torso = character:WaitForChild("UpperTorso")
	rightArm = character:WaitForChild("RightUpperArm")
	neck = head:WaitForChild("Neck")
	rightShoulder = rightArm:WaitForChild("RightShoulder")
end

local function onRenderStep()
	local state = humanoid:GetState()
	if not state then return end
	if state == Enum.HumanoidStateType.Swimming then return end
	local mousePosition = mouse.Hit.Position
	local toMouse = (mousePosition - head.Position).Unit
	local angle = math.acos(toMouse:Dot(Vector3.new(0, 1, 0)))
	local neckAngle = angle

	if math.deg(neckAngle) > 110 then
		neckAngle = math.rad(110)
	end

	if humanoid.RigType == Enum.HumanoidRigType.R6 then
		neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(math.pi - neckAngle, math.pi, 0)
	elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
		neck.C0 = CFrame.new(0, 0.84, 0) * CFrame.Angles(math.pi/2 - neckAngle, 0, 0)
	end
	
	local fromArmPos = torso.Position + torso.CFrame:vectorToWorldSpace(Vector3.new(torso.Size.X/2 + rightArm.Size.X/2, torso.Size.Y/2 - rightArm.Size.Z/2, 0))
	local toMouseArm = ((mousePosition - fromArmPos) * Vector3.new(1, 0, 1)).Unit
	local look = (torso.CFrame.lookVector * Vector3.new(1, 0, 1)).Unit
	local lateralAngle = math.acos(toMouseArm:Dot(look))

	if tostring(lateralAngle) == "-1.#IND" then
		lateralAngle = 0
	end
	
	if state == Enum.HumanoidStateType.Seated then
		local cross = root.CFrame.lookVector:Cross(toMouseArm)
		if lateralAngle > math.pi/2 then
			lateralAngle = math.pi/2
		end
		if cross.Y < 0 then
			lateralAngle = -lateralAngle
		end
	end	

	if humanoid.RigType == Enum.HumanoidRigType.R6 then
		rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(math.pi/2 - angle, math.pi/2 + lateralAngle, 0)
	elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
		rightShoulder.C0 = CFrame.new(1.25, 0.5, 0) * CFrame.Angles(math.pi/2 - angle, lateralAngle, 0)
	end

	if state ~= Enum.HumanoidStateType.Seated then
		root.CFrame = CFrame.lookAt(root.Position, root.Position + (Vector3.new(mousePosition.X, root.Position.Y, mousePosition.Z) - root.Position).Unit)
	end
	
	remote:FireServer(neck.C0, rightShoulder.C0)
end

run.RenderStepped:Connect(onRenderStep)
--SERVER

local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.RemoteEvent

local function onRemoteFired(player, neckC0, rightShoulderC0)
	local character = player.Character
	if not character then return end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end
	if humanoid.Health <= 0 then return end
	if humanoid.RigType == Enum.HumanoidRigType.R6 then
		local torso = character.Torso
		local neck = torso.Neck
		local rightShoulder = torso["Right Shoulder"]
		neck.C0 = neckC0
		rightShoulder.CO = rightShoulderC0
	elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
		local head = character.Head
		local neck = head.Neck
		local rightArm = character.RightUpperArm
		local rightShoulder = rightArm.RightShoulder
		neck.C0 = neckC0
		rightShoulder.C0 = rightShoulder.C0
	end
end

remote.OnServerEvent:Connect(onRemoteFired)

Here’s the place file for anyone that needs it.
Mouse.rbxl (27.9 KB)

3 Likes

rightShoulder.C0 = rightShoulder.C0 should be rightShoulder.C0 = rightShoulderC0 in server script :smiley:

dunno if you found a fix yet, but i got it working by literally just adding a wait(10) at the very beginning of the server script

1 Like

This was a really good script, buuuut it wouldn’t work with multiple players, here’s a fully fixed (and modified) version if anyone needs it

--LOCAL SCRIPT (put in StarterPlayer.StarterPlayerScripts)

local RunService = game:GetService("RunService")
---------------------------------------------------------------------
local GetLocalData = game:GetService("ReplicatedStorage"):WaitForChild(script.Parent.Parent.Name .."GetLocalData")
local GetMouseFollowFunction = game:GetService("ReplicatedStorage"):WaitForChild(script.Parent.Parent.Name .."GetMouseFollowFunction")
--(iii)
---------------------------------------------------------------------
local CameraSubject = workspace.CurrentCamera.CameraSubject -- (iv)

GetLocalData:FireServer()-- (v)


RunService.RenderStepped:Connect(function()
	local PlayerMouseHit = game.Players.LocalPlayer:GetMouse().Hit.p -- (vii)
	GetMouseFollowFunction:FireServer(CameraSubject,PlayerMouseHit) -- (viii)
end)
--SERVER SCRIPT (put in ServerScriptService)
--Also sorry if this looks kinda janky but ok

game.Players.PlayerAdded:Connect(function(plradded)
	plradded.CharacterAdded:Connect(function(charadded)

local GetLocalData = Instance.new("RemoteEvent")
local GetMouseFollowFunction = Instance.new("RemoteEvent")

		GetLocalData.Name = plradded.Name .."GetLocalData"
GetLocalData.Parent = game:GetService("ReplicatedStorage")

GetMouseFollowFunction.Name = plradded.Name .."GetMouseFollowFunction"
GetMouseFollowFunction.Parent = game:GetService("ReplicatedStorage")
-- (i)
---------------------------------------------------------------------
local Camera = game.Workspace.CurrentCamera

local Player
local Character

local Head
local Neck

local Arm
local Shoulder

local Humanoid
local HumanoidRootPart

local NeckOriginC0
local ShoulderOriginC0

-- (ii)
---------------------------------------------------------------------

GetLocalData.OnServerEvent:Connect(function(plr)
	
	Character = plr.Character or plr.CharacterAdded:Wait()
	
	Head = Character:WaitForChild("Head")
	Neck = Head:WaitForChild("Neck")
	
	Arm = Character:WaitForChild("RightUpperArm")
	Shoulder = Arm:WaitForChild("RightShoulder")
	
	Humanoid = Character:WaitForChild("Humanoid")
	HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	
	NeckOriginC0 = Neck.C0
	ShoulderOriginC0 = Shoulder.C0

	Neck.MaxVelocity = 3/3
end)
-- (vi) 
---------------------------------------------------------------------


GetMouseFollowFunction.OnServerEvent:Connect(function(_,CameraSubject,PlayerMouseHit)
	local CameraCFrame = Camera.CoordinateFrame



	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then

		local ArmLookVector = Arm.CFrame.lookVector

		local HeadPosition = Head.CFrame.p



		if Neck and Shoulder then

			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then

				local Point = PlayerMouseHit



				local Distance = (Head.CFrame.p - Point).magnitude
				local Difference = Head.CFrame.Y - Point.Y
						
				Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
				if Character:FindFirstChildWhichIsA("Tool") then
					Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
				else
					Shoulder.C0 = ShoulderOriginC0
				end

			end

		end

	end
end)

-- (ix)
	---------------------------------------------------------------------
end)
end)

My modified version only moves the head and the right hand (if holding a tool) of the player (it can be mixed with the original script to move the torso too), it also works fine for all players, make sure to give Workspace.Camera a CameraSubject (I personally made the Workspace itself the CameraSubject) or it will break, Thanks for your AWESOME script @Anurag_UdayS :+1:

1 Like

Allight NOW this is the last time im touching Motor6D stuff because my head hurts, final script, supports multiple players, both R6 and R15 avatars, and still works even after death, again make sure to make workspace the camera’s camera subject or it wont work,

--local script (goes in StarterPlayer.StarterPlayerScripts

game.Players.LocalPlayer.CharacterAdded:Connect(function(charadded)
	local RunService = game:GetService("RunService")
---------------------------------------------------------------------
	local GetLocalData = game:GetService("ReplicatedStorage"):WaitForChild(script.Parent.Parent.Name .."GetLocalData")
	local GetMouseFollowFunction = game:GetService("ReplicatedStorage"):WaitForChild(script.Parent.Parent.Name .."GetMouseFollowFunction")
--(iii)
---------------------------------------------------------------------
	local CameraSubject = workspace.CurrentCamera.CameraSubject -- (iv)

	GetLocalData:FireServer()-- (v)


	RunService.RenderStepped:Connect(function()
		local PlayerMouseHit = game.Players.LocalPlayer:GetMouse().Hit.p -- (vii)
		GetMouseFollowFunction:FireServer(CameraSubject,PlayerMouseHit) -- (viii)
	end)
end)
--server script (goes in ServerScriptService)

game.Players.PlayerAdded:Connect(function(plradded)
	repeat
		wait()
	until plradded.Character

	local GetLocalData = Instance.new("RemoteEvent")
	local GetMouseFollowFunction = Instance.new("RemoteEvent")

	GetLocalData.Name = plradded.Name .."GetLocalData"
	GetLocalData.Parent = game:GetService("ReplicatedStorage")

	GetMouseFollowFunction.Name = plradded.Name .."GetMouseFollowFunction"
	GetMouseFollowFunction.Parent = game:GetService("ReplicatedStorage")
	-- (i)
	---------------------------------------------------------------------
	local Camera = game.Workspace.CurrentCamera

	local Player
	local Character

	local Head
	local Neck

	local Torso

	local Arm
	local Shoulder

	local Humanoid
	local HumanoidRootPart

	local NeckOriginC0
	local ShoulderOriginC0
	
	local tname

	-- (ii)
	---------------------------------------------------------------------

	GetLocalData.OnServerEvent:Connect(function(plr)

		Character = plr.Character or plr.CharacterAdded:Wait()

		if Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
			Head = Character:WaitForChild("Head")
			Torso = Character:WaitForChild("Torso")
			Neck = Torso:WaitForChild("Neck")



			Arm = Character:WaitForChild("Right Arm")
			Shoulder = Torso:WaitForChild("Right Shoulder")
		elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
			Head = Character:WaitForChild("Head")
			Neck = Head:WaitForChild("Neck")

			Arm = Character:WaitForChild("RightUpperArm")
			Shoulder = Arm:WaitForChild("RightShoulder")
			
			Torso = Character:WaitForChild("UpperTorso")
		end


		Humanoid = Character:WaitForChild("Humanoid")
		HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

		NeckOriginC0 = Neck.C0
		ShoulderOriginC0 = Shoulder.C0

		Neck.MaxVelocity = 1
	end)
	-- (vi) 
	---------------------------------------------------------------------


	GetMouseFollowFunction.OnServerEvent:Connect(function(_,CameraSubject,PlayerMouseHit)
		local CameraCFrame = Camera.CoordinateFrame



		if Character:FindFirstChild(Torso.Name) and Character:FindFirstChild("Head") then

			local ArmLookVector = Arm.CFrame.lookVector

			local HeadPosition = Head.CFrame.p



			if Neck and Shoulder then

				if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then

					local Point = PlayerMouseHit



					local Distance = (Head.CFrame.p - Point).magnitude
					local Difference = Head.CFrame.Y - Point.Y

					if Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
						Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
						if Character:FindFirstChildWhichIsA("Tool") then
							Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
						else
							Shoulder.C0 = ShoulderOriginC0
						end
					elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
						Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles((math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
						if Character:FindFirstChildWhichIsA("Tool") then
							Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(0, (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, -(math.asin(Difference / Distance))), .5 / 2)
						else
							Shoulder.C0 = ShoulderOriginC0
						end
					end

				end

			end

		end

	end
	)

	-- (ix)
	---------------------------------------------------------------------
end)

enjoy

1 Like

Man, how I can use that for everybody on the server see?
I need send that for the server, but how is the best way for that? I only send a lot of events for the server? I think that’s not a good way.

Bump for @Notaflusson2.

It’s actually possible to work with R6 with a little CFrame inversing even though the waist is missing. I have done so in the post below:

4 Likes

Hey man i understand the logic of this thx