How would i make an idle animation?

  1. What do you want to achieve?
    i want to be able to have an idle animation play, and stop when either the walk or jumping animation is playing. i’ve come across where the idle animation will want to play while the jumping animation is starting

  2. What is the issue?

  3. What solutions have you tried so far?
    i’ve tried to load the animation but then i come across where the jumping animation won’t play correctly when the idle was playing before it, but the walking animation plays perfectly with the jumping animation? right now i don’t have the idle code in because it just messes things up

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))


humanoid.Running:Connect(function(speed)
	if speed > .1 then 
		if not walkAnim.IsPlaying then
			walkAnim:Play()
		end
		walkAnim:AdjustSpeed(speed/16)
	else
		if walkAnim.IsPlaying then 
			walkAnim:Stop()
		end
	end
end)

humanoid.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Jumping then
		jumpAnim:Play()
	elseif new == Enum.HumanoidStateType.Landed then
		jumpAnim:Stop()
	end
end)```

use rootPart.AssemblyLinearVelocity.Magnitude. check if it is zero, and if it is, play the idle animation. otherwise play the walking animation. very crude way of doing this but someone will definitely reply with a better idea

so how would that look altogether? i had to watch a tutorial to get those code, i am very much still new to learning this code

rootpart:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function(Value) 
   local Velocity = Value.Magnitude or 0
   if Velocity > 0 then
      -- play walk
   elseif Velocity == 0 then
      -- play idle
   end
end)

cant quite remember what :GetPropertyChangedSignal’s first parameter is but it should help you enough

yea nah unfortunately no animations are playing then

made a mistake, :GetPropertyChangedSignal doesn’t fire for physics updates like velocity so just use a runservice.heartbeat connection and check if the velocity is 0 from there.

:smiling_face_with_tear: i don’t know what that means or where to put it if i’m going to be honest, sorry if i’m being a bit but i really want to know what these things mean and how to put them in

local RunService = game:GetService("RunService")

---... your existing code
local function animateVelocity(Velocity)
    if Velocity > 0 then
        -- play walk
    else
       -- play idle
    end
end

RunService.Heartbeat:Connect(function() 
    local currentVelo = RootPart.AssemblyLinearVelocity.Magnitude -- assuming you referenced your rootpart already
    animateVelocity(currentVelo)
end)

okay i put it in, it has no red underline, the other animations play just fine but the idle isnt loading

replace else with elseif velocity == 0

the animations just don’t load what soever now unfortunately

here let me just

local character = script.Parent
local RunService = game:GetService("RunService")
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))

humanoid.Running:Connect(function(speed)
	if speed > .1 then 
		if not walkAnim.IsPlaying then
			walkAnim:Play()
		end
		walkAnim:AdjustSpeed(speed/16)
	else
		if walkAnim.IsPlaying then 
			walkAnim:Stop()
		end
	end
end)

humanoid.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Jumping then
		jumpAnim:Play()
	elseif new == Enum.HumanoidStateType.Landed then
		jumpAnim:Stop()
	end
end)


local function animateVelocity(Velocity)
	if Velocity > 0 then
		walkAnim:Play()
	else
		idleAnim:Play()
	end
end

RunService.Heartbeat:Connect(function() 
	local currentVelo = humanoid.AssemblyLinearVelocity.Magnitude 
	animateVelocity(currentVelo)
end)

you’re using humanoid.AssemblyLinearVelocity brotato chip :broken_heart: use RootPart.AssemblyLinearVelocity

.AssemblyLinearVelocity only exists for actual parts, not humanoids.


yea but then it gives a red underline and still doesn’t work? at least with the humanoid it doesn’t have the red? i can’t tell if it’s better with the humanoid

right… i forgot you were a beginner. no worries! you just have to reference it where you put RunService.

local RunService = game:GetService("RunService")
local RootPart = character:FindFirstChild("HumanoidRootPart")

red line under something means Luau is trying to tell you something is wrong with what you typed, in your case you didn’t have a reference to RootPart, so it thinks there is no RootPart.

okay, slightly new problem


there is only the animation error now

local character = script.Parent
local RunService = game:GetService("RunService")
local RootPart = character:FindFirstChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))

RootPart.Running:Connect(function(speed)
	if speed > .1 then 
		if not walkAnim.IsPlaying then
			walkAnim:Play()
		end
		walkAnim:AdjustSpeed(speed/16)
	else
		if walkAnim.IsPlaying then 
			walkAnim:Stop()
		end
	end
end)

RootPart.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Jumping then
		jumpAnim:Play()
	elseif new == Enum.HumanoidStateType.Landed then
		jumpAnim:Stop()
	end
end)


local function animateVelocity(Velocity)
	if Velocity > 0 then
		walkAnim:Play()
	else
		idleAnim:Play()
	end
end

RunService.Heartbeat:Connect(function() 
	local currentVelo = RootPart.AssemblyLinearVelocity.Magnitude 
	animateVelocity(currentVelo)
end)

image


where did the other references go?

i’m going to be so honest it’s late as hell for me i don’t know what i’m doing and my brain is NOT working :sob:

'm just going to keep it at wraps for now, thank you so much for helping even if me not knowing how half of this works probably contributed to it not working- sorry again if this felt like a waste i promise i am trying to learn this all

if anyone else finds out what i am doing wrong lemme know or if there is other code to use

Hey there! Is there a particular reason why you’re using your own script for your custom animations? Why don’t you simply modify the in-built animate script to work with your rig and use custom animations instead of the pre-defined default Roblox animations?