Characters in my game got bugged movement animations

Walking animations for players are bugged in my game because of a Camera script.
You can call me Z14 for short.

All animations, except walking, are bugged. There is a strange stuttering/lag effect.
I used the Team Playtest for the recording of the video,
Example:

I have tried looking about this topic online, but I still got no answers

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the main camera script:

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 
								-- StarterGui -- 					
--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--
--	Place this into StarterGui or StarterPack							--
--	CREDIT																--
--	WhoBloxxedWho; for the initial script								--
--	DoogleFox; some stuff ripped from his panner script					--
--	DuruTeru; shoving it all into this script and then some :)			--
--	UPDATE: turned it into r15, made it so you can swim right in water	--
--  Jan 07, 2017														--
--  UPDATE: added walkspeed easing directionally, also adding running   --	
--  Nov 13, 2020														--
--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--


---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 


repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")

-- you can mess with these settings
CanToggleMouse = {allowed = true; activationkey = Enum.KeyCode.M;} -- lets you move your mouse around in firstperson
CanViewBody = true 		-- whether you see your body
Sensitivity = 0.65		-- anything higher would make looking up and down harder; recommend anything between 0~1
Smoothness = 0.065		-- recommend anything between 0~1
HeadOffset = CFrame.new(0,0,0) -- how far your camera is from your head

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local m = player:GetMouse()
local character = player.Character or player.CharacterAdded:wait()
local human = character.Humanoid
local humanoidpart = character.HumanoidRootPart

local head = character.Head:WaitForChild("FPCamera")
local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p 
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0

local running = false
local freemouse = false

local w, a, s, d = false, false, false, false

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

function updatechar()
	
	for _, v in pairs(character:GetChildren())do
		if CanViewBody then
			if v.Name == 'Head' then
				v.LocalTransparencyModifier = 0.7
				v.CanCollide = false
				v.face.LocalTransparencyModifier = 1
			end
		else
			if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
				v.LocalTransparencyModifier = 1
				v.CanCollide = false
			end
		end
		if v:IsA'Hat' then
			if v.AccessoryType == Enum.AccessoryType.Hat then
				v:FindFirstChild('Handle').LocalTransparencyModifier = 1
				v:FindFirstChild('Handle').CanCollide = false
			end
		end
		if v:IsA'Accessory' then
			if v.AccessoryType == Enum.AccessoryType.Hat then
				v:FindFirstChild('Handle').LocalTransparencyModifier = 1
				v:FindFirstChild('Handle').CanCollide = false
			end
		end
		if v:IsA'Accessory' then
			if v.AccessoryType == Enum.AccessoryType.Hair then
				v:FindFirstChild('Handle').LocalTransparencyModifier = 1
				v:FindFirstChild('Handle').CanCollide = false
			end
		end

	end
	
end

-- math, thx roblox wiki
function lerp(a, b, t)
	return a * (1-t) + (b*t)
end


---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

input.InputChanged:connect(function(inputObject)
	
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness

		local X = TargetAngleX - delta.y 
		TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
		TargetAngleY = (TargetAngleY - delta.x) %360 
	end	
	
end)

input.InputBegan:connect(function(inputObject)
	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == CanToggleMouse.activationkey then
			if CanToggleMouse.allowed and freemouse == false then
				freemouse = true
			else
				freemouse = false
			end
		end
	end
	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == Enum.KeyCode.W then
			w = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.A then
			a = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.S then
			s = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.D then
			d = true
		end
		
	end
end)

input.InputEnded:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == Enum.KeyCode.W then
			w = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.A then
			a = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.S then
			s = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.D then
			d = false
		end
		
	end
end)

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

runService.RenderStepped:connect(function()
	 
	if running then
		updatechar()
		
		CamPos = CamPos + (TargetCamPos - CamPos) *0.28 
		AngleX = AngleX + (TargetAngleX - AngleX) *0.35 
		local dist = TargetAngleY - AngleY 
		dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist 
		AngleY = (AngleY + dist *0.35) %360
		cam.CameraType = Enum.CameraType.Scriptable
		
		cam.CoordinateFrame = CFrame.new(head.Position) 
		* CFrame.Angles(0,math.rad(AngleY),0) 
		* CFrame.Angles(math.rad(AngleX),0,0)
		* HeadOffset -- offset
		
		humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
		else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
	end

	if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
		running = false
	else
		running = true
		if freemouse == true then
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
		else
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
		end
	end
	
	if not CanToggleMouse.allowed then
		freemouse = false
	end
	
		
end)

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

This is the FPCamera script (This script creates a part that is locked to the head for the script above to use as the camera. I did this so that the camera rotates in right axis):

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")

-- Criar a FPCamera --
local parteTransparente = Instance.new("Part")
parteTransparente.Name = 'FPCamera'
parteTransparente.Transparency = 1 -- Transparencia
parteTransparente.CastShadow = false -- Transparencia
parteTransparente.Size = Vector3.new(1.25, 1.25, 0.5) -- Tamanho
parteTransparente.CanCollide = false -- Coisão
parteTransparente.Anchored = true
parteTransparente.Parent = head
----

-- Função para atualizar a posição da parte transparente
local function atualizarPosicao()
	parteTransparente.CFrame = head.CFrame * CFrame.new(0, 0.15, -0.3) -- Ajuste a posição conforme necessário
end

-- Atualizar a posição da parte transparente quando necessário
game:GetService("RunService").RenderStepped:Connect(function()
	atualizarPosicao()
end)

-- Adicione a parte transparente à cabeça do jogador
parteTransparente.Parent = head

Any help will make me already happy.

1 Like