Character rotates after looking too far

I have already made a similar post and made something close to what I wanted to achieve, although, I still have one small problem.

There is a localscript I used from this post:

But I would like to get a short explanation on how to make this work for R6.

I am only trying to get the body to rotate left or right after looking too far.

^^^
I want to achieve this but for R6

The code in the post above:

-- StarterCharacterScripts

local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local char = player.Character
local human = char:WaitForChild("Humanoid")
local rootPart = char.PrimaryPart
local upperTorso = char:WaitForChild("UpperTorso")
local waistJoint = upperTorso:WaitForChild("Waist")

-- Services
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")

-- Globals
local currentSpeed = 0;
local currentTween = nil;

human.AutoRotate = false

human.Running:Connect(function(speed)
	currentSpeed = speed
	if speed > 0 then
		human.AutoRotate = true
	end
end)

human.Running:Connect(function(speed)
	currentSpeed = speed
	if speed <= 0 then
		human.AutoRotate = false
	end
end)



local originalWaistC1 = waistJoint.C1
local maxRotation = math.rad(85)
runService:BindToRenderStep("vanityCamera", 400, function()
	local targetPosition = (cam.CFrame * CFrame.new(0,0,-1000)).p
	local torsoFront = rootPart.CFrame.LookVector
	local torsoRight = rootPart.CFrame.RightVector
	local vectorToTarget = (targetPosition - rootPart.Position)
	local rotation = math.atan2(torsoRight:Dot(vectorToTarget), torsoFront:Dot(vectorToTarget))

	-- Clamp the rotation
	if (rotation < -maxRotation) then
		rotation = -maxRotation
	elseif (rotation > maxRotation) then
		rotation = maxRotation
	end

	if (math.abs(rotation) == maxRotation and currentSpeed <= 0.5) then
		-- Rotate the bottom half to face the new direction
		local newRootPartCFrame = CFrame.new(rootPart.Position, Vector3.new(
			targetPosition.X, rootPart.Position.Y, targetPosition.Z
			))
		currentTween = tweenService:Create(rootPart, TweenInfo.new(0.33), {
			CFrame = newRootPartCFrame
		})
		currentTween:Play()
	else
		if (currentTween and currentSpeed > 0.5) then
			if (currentTween.PlaybackState == Enum.PlaybackState.Playing) then
				currentTween:Cancel()
			end
		end

		waistJoint.C1 = CFrame.Angles(0,rotation,0) * originalWaistC1
	end

end)
1 Like

so do you want the script to work with r6? because im a little confused

1 Like

Yes, thats exactly what im aiming for

1 Like

well, im not sure how you could create it, because r15 has character body parts like upper torso, waist, and with r6, you can only move the torso

Do you want to move only the torso?

If im correct, if the HumanoidRootPart is rotated, all of the other body parts also rotate with it?

i think so, since its the root of the character, and all other parts are connected to it by Motor6D joints

I still haven’t managed to get it to work for R6, is there any short explanation you can give me so I can make it work for it?

well you could try rotating the torso

You just need to change some stuff in the script

you’d just need to change

local rootPart = char.PrimaryPart
local upperTorso = char:WaitForChild("UpperTorso")
local waistJoint = upperTorso:WaitForChild("Waist")

to

local rootPart = char:WaitForChild("HumanoidRootPart")
local upperTorso = char:WaitForChild("Torso")
local waistJoint = upperTorso:WaitForChild("Neck")