My character starts rotating when i look down

I’m using a script that i found in the toolbox, and i re-wrote it for a FPS system that i’m creating. But after some adjusts that i did in my game (i only remember of changing the CameraModule.TransparencyController), this script made by character walk like if he was spinning.

All things that i changed in the CameraModule.TransparencyController was to add a for loop that made all the acessories invisible.

Here is the script that i re-wrote:

local Camera = game.Workspace.CurrentCamera
local Damping = Character.Humanoid.WalkSpeed / 1.5
local PI = math.pi
local Ticks = PI / 2
local isRunning = false
local isStrafing = false

game:GetService("RunService").RenderStepped:Connect(function()
	
	if isRunning and not isStrafing then
		Ticks += Character.Humanoid.WalkSpeed / 92
	else
		if Ticks > 0 and Ticks < PI / 2 then
			Ticks = LinearInterpolation(Ticks, PI / 2, 0.9)
		end
		
		if PI / 2 < Ticks and Ticks < PI then
			Ticks = LinearInterpolation(Ticks, PI / 2, 0.9);
		end
		
		if PI < Ticks and Ticks < PI * 1.5 then
			Ticks = LinearInterpolation(Ticks, PI * 1.5, 0.9);
		end
		
		if PI * 1.5 < Ticks and Ticks < PI * 2 then
			Ticks = LinearInterpolation(Ticks, PI * 1.5, 0.9)
		end 
	end

	if PI * 2 <= Ticks then
		Ticks = 0
	end
	
	Camera.CFrame = (
		Camera.CFrame
		-------
		* CFrame.new(
			math.cos(Ticks) / Damping,
			-------
			math.sin(Ticks * 2) / (Damping * 2),
			-------
			0
		)
		-------
		* CFrame.Angles(
			0,
			0,
			math.sin(Ticks - PI * 1.5) / (Damping * 20)
		)
	)
end)

And here is a video of what is happening:

Any ideas on how to fix this?

OBS: My character didn’t spinned that much because i put a limitator on where my camera can look

#help-and-feedback:scripting-support

4 Likes