Help with the camera jittering

Hello everyone! This is my first post here and I’ve encountered a problem with the camera while im working on my project.

So basically i have this force shiftlock local script(not mine)

local plr = game.Players.LocalPlayer
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local CC = game.Workspace.CurrentCamera
local button = script.Parent.MenuGui.Frame.startButton

button.MouseButton1Up:Connect(function()
char:FindFirstChild("Humanoid").CameraOffset = Vector3.new(1,1,0)
game:GetService("RunService").RenderStepped:Connect(function()
if UIS.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end

local pos = hrp.Position + Vector3.new(CC.CFrame.LookVector.X, 0, 
CC.CFrame.LookVector.Z)

	hrp.CFrame = CFrame.new(hrp.Position, pos)
end)
end)

It works as expected until some weird animations get played.

The camera movement is real jittery when going backwards. I think this is because of the slight leaning in the walk animation?

I would be glad if someone pointed out the problem, thanks for your time!

i tried script on my roblox studio and when i used Heartbeat instead of RenderStepped issue gone

can you try that please

It works but also creates another problem, instead of the camera the players movement gets jittery

how about you combine RenderStepped and Heartbeat

local plr = game.Players.LocalPlayer
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local run = game:GetService("RunService")
local CC = game.Workspace.CurrentCamera
local button = script.Parent.MenuGui.Frame.startButton

local function step()
	if UIS.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	end
	local pos = hrp.Position + Vector3.new(CC.CFrame.LookVector.X, 0, CC.CFrame.LookVector.Z)
	hrp.CFrame = CFrame.new(hrp.Position, pos)
end

button.MouseButton1Up:Connect(function()
	char:FindFirstChild("Humanoid").CameraOffset = Vector3.new(1,1,0)
	run.RenderStepped:Connect(step)
	run.Heartbeat:Connect(step)
end)
1 Like

Works perfectly! Thanks for the help.