Directional Movement Works Weird

I want to achieve right directional movement system.
The issue is when I start moving forward left or backward right, my character’s legs start to move so weird
I tried changing my code but it doesn’t helped actually, I tried playing with values a bit but the problem is the same anyways.
Also is it possible that the problem is with the animations?

Script:

local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Char = script.Parent
local Hum = Char:FindFirstChildOfClass("Humanoid")
local HRP = Char:FindFirstChild("HumanoidRootPart")

local Animations = {}

for i, v in pairs(script.Animations:GetChildren()) do
	
	Animations[v.Name] = Hum:LoadAnimation(v)
	Animations[v.Name]:Play(0, 0.01, 0)
end

RunService.RenderStepped:Connect(function()
	
	local DirOfMovement = HRP.CFrame:VectorToObjectSpace(HRP.AssemblyLinearVelocity)
	
	local Forward = math.abs(math.clamp(DirOfMovement.Z / Hum.WalkSpeed, -1, 0.001))
	local Backwards = math.abs(math.clamp(DirOfMovement.Z / Hum.WalkSpeed, 0.001, 1))
	local Right = math.abs(math.clamp(DirOfMovement.X / Hum.WalkSpeed, 0.001, 1))
	local Left = math.abs(math.clamp(DirOfMovement.X / Hum.WalkSpeed, -1, 0.001))
	
	if DirOfMovement.Z / Hum.WalkSpeed < 0.1 then
		
		Animations.WalkForward:AdjustWeight(Forward)
		Animations.WalkRight:AdjustWeight(Right)
		Animations.WalkLeft:AdjustWeight(Left)
		
		Animations.WalkForward:AdjustSpeed(DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5)
		Animations.WalkRight:AdjustSpeed(DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5)
		Animations.WalkLeft:AdjustSpeed(DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5)
	
	else
		
		Animations.WalkForward:AdjustWeight(Backwards)
		Animations.WalkRight:AdjustWeight(Left)
		Animations.WalkLeft:AdjustWeight(Right)
		
		Animations.WalkForward:AdjustSpeed((DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5) * -1)
		Animations.WalkRight:AdjustSpeed((DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5) * -1)
		Animations.WalkLeft:AdjustSpeed((DirOfMovement.Magnitude / Hum.WalkSpeed + 0.5) * -1)
	end
end)

1 Like