To fix the issue with the arms and legs, we need to adjust the rotation axes and signs. Here's an updated version of the script:
-- 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.
-- (This script assumes an R6 rig; adjust accordingly if you’re using R15.)
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 as needed.)
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(30) -- Base amplitude for arm/leg swings
local headBobAmount = math.rad(2) -- Subtle head bobbing
local jumpArmAngle = math.rad(45) -- Angle to raise arms during jump
-- Timer variable for tracking elapsed time in the 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
-- === JUMPING 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) ===
local swing = math.sin(elapsedTime * walkSpeedFactor) * walkSwingAmount
-- Arms swing: Rotate the shoulders around the X-axis.
leftShoulder.C0 = origLSC0 * CFrame.Angles(0, 0, -swing)
rightShoulder.C0 = origRSC0 * CFrame.Angles(0, 0, swing)
-- Legs swing: Rotate the hips around the X-axis.
leftHip.C0 = origLHC0 * CFrame.Angles(-swing, 0, 0)
rightHip.C0 = origRHC0 * CFrame.Angles(swing, 0, 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)
The changes made were:
-
For the arms, the rotation is now around the Z-axis (as before), but the sign is inverted for one of the shoulders. This is done by changing leftShoulder.C0 = origLSC0 * CFrame.Angles(0, 0, swing) to leftShoulder.C0 = origLSC0 * CFrame.Angles(0, 0, -swing) and rightShoulder.C0 = origRSC0 * CFrame.Angles(0, 0, -swing) to rightShoulder.C0 = origRSC0 * CFrame.Angles(0, 0, swing). This makes the arms swing in opposite directions.
-
The legs are now rotating around the X-axis, which is more natural for a walking motion. The signs are also adjusted so that when one leg is forward, the other is backward.
With these changes, the arms and legs should now be swinging in a more natural and opposite manner.