-- Services local Players = game:GetService("Players") local RunService =…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
-- 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.
Torso which is deprecated in R15 characters. In R15 characters, the equivalent is UpperTorso.Torso with certain children (e.g., Neck, Left Shoulder, etc.). If the character is R15, these joints are not direct children of UpperTorso.torso.CFrame which can conflict with other scripts. Instead, we should modify the C0 or C1 of the relevant joints.-- 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 humanoid to exist
local humanoid = character:WaitForChild("Humanoid")
-- Determine if the character is R15 or R6
local isR15 = humanoid.RigType == Enum.HumanoidRigType.R15
-- Get the root part and humanoid root part
local rootPart = character:WaitForChild(isR15 and "UpperTorso" or "Torso")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Get the key joints
local neck, leftShoulder, rightShoulder, leftHip, rightHip
if isR15 then
local root = humanoidRootPart:WaitForChild("Root")
neck = root:WaitForChild("Neck")
leftShoulder = character:WaitForChild("LeftUpperArm"):WaitForChild("LeftShoulder")
rightShoulder = character:WaitForChild("RightUpperArm"):WaitForChild("RightShoulder")
leftHip = root:WaitForChild("LeftHip")
rightHip = root:WaitForChild("RightHip")
else
neck = rootPart:WaitForChild("Neck")
leftShoulder = rootPart:WaitForChild("Left Shoulder")
rightShoulder = rootPart:WaitForChild("Right Shoulder")
leftHip = rootPart:WaitForChild("Left Hip")
rightHip = rootPart:WaitForChild("Right Hip")
end
-- 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 = humanoidRootPart.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
-- Instead of modifying torso.CFrame, we modify the Root C0 to achieve a similar effect.
if isR15 then
humanoidRootPart.RootJoint.C0 = humanoidRootPart.RootJoint.C0 * CFrame.Angles(0, twist, 0)
end
-- 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)
UpperTorso and HumanoidRootPart, while for R6 characters, they are accessed directly through the Torso.torso.CFrame with a modification of the RootJoint.C0. This achieves a similar effect without conflicting with other scripts that may modify the torso.CFrame.LocalScript inside StarterScripts in your Roblox project.