-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

-- Get the player and wait for the character to load
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

-- Wait for the torso and humanoid to exist
local torso = character:WaitForChild("Torso")
local humanoid = character:WaitForChild("Humanoid")

-- Get the key joints
local neck = torso:WaitForChild("Neck")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftHip = torso:WaitForChild("Left Hip")
local rightHip = torso:WaitForChild("Right Hip")

-- Store the original C0 offsets for each joint so we can apply offsets on top
local origNeckC0 = neck.C0
local origLSC0 = leftShoulder.C0
local origRSC0 = rightShoulder.C0
local origLHC0 = leftHip.C0
local origRHC0 = rightHip.C0

-- Parameters (tweak these to fit your character's style)
local idleBreatheSpeed = 2             -- Frequency for idle "breathing"
local idleBreatheAmount = math.rad(2)    -- Small head nod amount for idle

local walkSpeedFactor = 8              -- Frequency multiplier for walking swings
local walkSwingAmount = math.rad(15)     -- Base amplitude for arm/leg swings
local torsoTwistAmount = math.rad(3)     -- Slight torso twist for weight shift
local headBobAmount = math.rad(2)        -- Subtle head bobbing

local jumpArmAngle = math.rad(45)        -- Angle to raise arms during jump

-- Timer variable for our animation
local elapsedTime = 0

-- Main animation loop (using RenderStepped for smoother animation)
RunService.RenderStepped:Connect(function(dt)
	elapsedTime = elapsedTime + dt

	-- Determine the current state
	local currentState = humanoid:GetState()
	local velocityMag = torso.Velocity.Magnitude

	if currentState == Enum.HumanoidStateType.Jumping or currentState == Enum.HumanoidStateType.Freefall then
		-- === JUMP POSE ===
		leftShoulder.C0 = origLSC0 * CFrame.Angles(-jumpArmAngle, 0, 0)
		rightShoulder.C0 = origRSC0 * CFrame.Angles(-jumpArmAngle, 0, 0)
		leftHip.C0 = origLHC0
		rightHip.C0 = origRHC0
		neck.C0 = origNeckC0

	elseif velocityMag < 1 then
		-- === IDLE POSE ===
		local breathe = math.sin(elapsedTime * idleBreatheSpeed) * idleBreatheAmount
		neck.C0 = origNeckC0 * CFrame.Angles(breathe, 0, 0)
		leftShoulder.C0 = origLSC0
		rightShoulder.C0 = origRSC0
		leftHip.C0 = origLHC0
		rightHip.C0 = origRHC0

	else
		-- === WALKING POSE (More Natural) ===
		-- Use a sine wave to drive the swing.
		local swing = math.sin(elapsedTime * walkSpeedFactor) * walkSwingAmount

		-- Arms: Rotate about the Z-axis so that they pivot forward/backwards.
		-- (Due to the default orientation, rotating around Z makes them swing forward rather than inward.)
		leftShoulder.C0 = origLSC0 * CFrame.Angles(0, 0, swing)
		rightShoulder.C0 = origRSC0 * CFrame.Angles(0, 0, -swing)

		-- Legs: Instead of rotating as before, we invert the rotation sign so that they swing straight.
		-- When swing is positive, we want the left leg to go backward (negative angle) and the right leg to go forward (positive angle).
		leftHip.C0 = origLHC0 * CFrame.Angles(-swing, 0, 0)
		rightHip.C0 = origRHC0 * CFrame.Angles(swing, 0, 0)

		-- Optional torso twist for a subtle weight shift:
		local twist = math.sin(elapsedTime * walkSpeedFactor) * torsoTwistAmount
		-- Note: Modifying torso.CFrame directly can conflict with other scripts, but it demonstrates the idea.
		torso.CFrame = torso.CFrame * CFrame.Angles(0, twist * dt, 0)

		-- Head bobbing: a subtle up and down motion.
		local headBob = math.sin(elapsedTime * walkSpeedFactor * 0.5) * headBobAmount
		neck.C0 = origNeckC0 * CFrame.Angles(headBob, 0, 0)
	end
end)
fix all errors in this procedural animation script in roblox.