How could I reset the player's head (or whatever object) orientation?

Hey everyone,

I’m making this gun that makes your torso and head follow your mouse once equipped, but when you unequip it, it doesn’t reset the head.

Example:

Can you show us the script please?

Why do I need to do so?

I got a simple equip and unequip function that makes a variable true, thus causing the torso and head to start moving around. The only thing I really need help making here is making the head go back to its original position.

Yeah I understand but it would be better to see what you have and easily add a fix, whereas I’m not sure how your system works for me to actually fix it.

Sorry I took a while writing I was trying to write a solution but not sure how your system works since there are many ways it can be made, I don’t think there is one fix to all. So if you could show or tell us the way your system works.

If you insist, prepare your eyes.

local Ang = CFrame.Angles
local aSin = math.asin
local aTan = math.atan
wait()local Cam = game.Workspace.CurrentCamera
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Body = Plr.Character or Plr.CharacterAdded:wait()
local Head = Body:WaitForChild("Head")
local Hum = Body:WaitForChild("Humanoid")
local Core = Body:WaitForChild("HumanoidRootPart")
local IsR6 = (Hum.RigType.Value==0)
local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso")
local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck")
local Waist = (not IsR6 and Trso:WaitForChild("Waist"))
-- might reuse so settings and stuff
local MseGuide = false
local TurnCharacterToMouse = true
local HeadHorFactor = 1
local HeadVertFactor = 0.6
local BodyHorFactor = 0.5
local BodyVertFactor = 0.4
local UpdateSpeed = 0.5
local NeckOrgnC0 = Neck.C0
local WaistOrgnC0 = (not IsR6 and Waist.C0)
Neck.MaxVelocity = 1/3

if TurnCharacterToMouse then
	MseGuide = true
	HeadHorFactor = 0
	BodyHorFactor = 0
end

eq = false

script.Parent.Equipped:Connect(function()
	eq = true
end)

script.Parent.Unequipped:Connect(function()
	eq = false
end)

-- loading code mess... (i mean, atleast it runs on the client?)

game:GetService("RunService").RenderStepped:Connect(function()
	local CamCF = Cam.CoordinateFrame
	if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil and eq then
		local TrsoLV = Trso.CFrame.lookVector
		local HdPos = Head.CFrame.p
		if IsR6 and Neck or Neck and Waist then
			if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
				local Dist = nil;
				local Diff = nil;
				if not MseGuide then
					Dist = (Head.CFrame.p-CamCF.p).magnitude
					Diff = Head.CFrame.Y-CamCF.Y
					if not IsR6 then
						Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
						Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
					else
						Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2)
					end
				else
					local Point = Mouse.Hit.p
					Dist = (Head.CFrame.p-Point).magnitude
					Diff = Head.CFrame.Y-Point.Y
					if not IsR6 then
						Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
						Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
					else
						Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2)
					end
				end
			end
		end
	end
	if TurnCharacterToMouse == true and eq then
		Hum.AutoRotate = false
		Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
	else
		Hum.AutoRotate = true
	end
end)

One question in the video you provided the head was already looking down? Is that how it spawns in or is that after you have selected your gun. I am assuming it’s after but in the video you can’t quite tell.

That’s after you equip the tool.

Alright, So what you could try is adding Neck.C0 = NeckOrgnC0 after the else on line 80.

Ah, ok. That didn’t work, but when I put it under the equip function it worked. Thanks

Oh right, so it works now? If so that’s good.

1 Like