The camera is glitching sometimes

This may sound weird, but there is like a 2/3 chance that the camera is glitching, I have no idea why this is happening and how to fix this.
This is how it’s supposed to be (Its focused on the Kunai, and the camera is not twitching):

And this is the glitched version:


You don’t really see it in this picture, but the camera is focused on the character and it keeps twitching, which is not visible in the picture.

These are the scripts:
This one is in the localscript:

local cam = workspace.CurrentCamera
repeat wait()
	cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
while wait() do
	cam.CFrame = game.Workspace:FindFirstChild("Kunai").Cambrick.CFrame
end

and this one is inside the cambrick to keep it in position:

while wait() do
	script.Parent.Position = script.Parent.Parent.Position + Vector3.new(0,25.7,0)
	script.Parent.Orientation = Vector3.new(-84.316, 0, 0)
end

Thank you for reading, have a nice day.

1 Like

Combine these loops. Instead of using repeat and while, use RunService.