Character glitches in forced Shift Lock Script?

Hola fellow Robloxians. I’ve been working on a game that utilizes a force shift-lock mode by using RunService. It technically works, but there’s an issue.

It’s overall, just very glitchy. When moving the camera around, your character kind of glitches back and forth, the entire screen does too, to an extent, but I have a reasonable doubt that the camera is the issue, and rather that everything glitches because of your head glitching, which is where the camera is based off of in First Person. This is a video of the janky-ness occuring:

As you can see, everything works fine, but your character has trouble keeping up with the camera turning. How could I fix this?

EDIT: Oh gosh, I forgot the code completely! It’s pretty simple though, here it is:
Script in StarterCharacterScripts:

local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local humanoid = player.Character.Humanoid

runService.RenderStepped:Connect(function()
	humanoid.CameraOffset = Vector3.new(2.5,0.5,2)
end)

I then configured a part of the CameraModule:

function CameraModule:Update(dt)
	if self.activeCameraController then
		if game.Players.LocalPlayer.PlayerScripts.ShiftLockToggle.ShiftLockToggle.Value == true then --Edited code, simple if-else statement
			self.activeCameraController:SetIsMouseLocked(true)
			
		else
			self.activeCameraController:SetIsMouseLocked(false)
		end
1 Like

Can you please show us your code? I can’t really help if there’s no code in the post. Thank you

Oops, can’t believe I forgot the code. I edited it to the end of the original post.

1 Like

You don’t need to make a connection to change the camera offset. Idk if I’m right or wrong but :Update() runs every frame just like RenderStepped, try changing the offset in the update function instead of creating a new one connection and then changing the offset.

How would I use :Update() in this situation?

I meant just change the camera offset in the function itself

Maybe you can try using the BindToRenderStep function instead of RenderStepped
Here is an example, although it is not the shift lock feature, this is an alternative.

local runService = game:GetService('RunService')
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local character = player.Character or player.CharacterAdded:Wait()

local function adjustCamera()
    camera.CFrame = CFrame.new(character.Torso.CFrame * CFrame.new(0, 0, 5)
end

runService:BindToRenderStep('CameraBehindPlayer', 201, adjustCamera)

Ah, I see. It does not work because you can not reference Character in the Camera Module Script.

We’re getting somewhere now. The lag doesn’t occur anymore, but despite me changing the CFrame.new() values, it always goes directly behind the player.

I’m going to bump this because we still aren’t getting anywhere and the extent of my entire brain can not solve this.

I am now using

if shiftLockToggle.Value == true then
		camera.CFrame = (character.Torso.Cframe + Vector3.new(1.5,2,5,2))
end

Yet it sits directly behind the player and will not budge. Anyone got any other ideas?