R6 idle animation not working

i have tried to make a movement detector to be able to set animation but its not working for some reason can someone please help me :pray:

local function setupAnimations(npc)
	local humanoid = npc:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)

	-- Load animations
	local walkAnimation = Instance.new("Animation")
	walkAnimation.AnimationId = "rbxassetid://83352974906298"

	local idleAnimation = Instance.new("Animation")
	idleAnimation.AnimationId = "rbxassetid://180435571" -- Replace with actual idle animation ID

	local walkTrack = animator:LoadAnimation(walkAnimation)
	local idleTrack = animator:LoadAnimation(idleAnimation)

	walkTrack.Looped = true
	idleTrack.Looped = true

	-- Play idle animation by default
	idleTrack:Play()

	-- Detect movement changes
	humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
		if humanoid.MoveDirection.Magnitude > 0 then
			-- NPC is walking
			if not walkTrack.IsPlaying then
				idleTrack:Stop()
				walkTrack:Play()
			end
		else
			-- NPC is idle
			if not idleTrack.IsPlaying then
				walkTrack:Stop()
				idleTrack:Play()
			end
		end
	end)
end

I have tried to use the default Roblox idle animation but it didn’t work for me if someone can explain me I will appreciate it a lot

1 Like

Perhaps the animation priority is set incorrectly? Try doing:
idletrack.Priority = Enum.AnimationPriority.Idle

Or maybe it’s the animation itself? Try uploading it yourself.

1 Like

i have tried to upload myself, didn’t work.

how do I set the priority, didn’t work

local function setupAnimations(npc)
	local humanoid = npc:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)

	-- Load animations
	local walkAnimation = Instance.new("Animation")
	walkAnimation.AnimationId = "rbxassetid://83352974906298"

	local idleAnimation = Instance.new("Animation")
	idleAnimation.AnimationId = "rbxassetid://95550775398729" -- Replace with actual idle animation ID

	local walkTrack = animator:LoadAnimation(walkAnimation)
	local idleTrack = animator:LoadAnimation(idleAnimation)
	idleTrack.Priority = Enum.AnimationPriority.Idle

	walkTrack.Looped = true
	idleTrack.Looped = true

	-- Play idle animation by default
	idleTrack:Play()

	-- Detect movement changes
	humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
		if humanoid.MoveDirection.Magnitude > 0 then
			-- NPC is walking
			if not walkTrack.IsPlaying then
				print(humanoid.MoveDirection.Magnitude)
				idleTrack:Stop()
				walkTrack:Play()
			end
		else
			-- NPC is idle
			if not idleTrack.IsPlaying then
				print("b "..humanoid.MoveDirection.Magnitude)
				walkTrack:Stop()
				idleTrack:Play()
			end
		end
	end)
end

:arrow_up:
you can see here that the npc’s walk but no animation.

if I set the idle animation to the same ID as the walk it works for walking
idleAnimation.AnimationId = "rbxassetid://83352974906298" -- Replace with actual idle animation ID

image

You settled the priority properly.

Perhaps try printing track.IsPlaying on random intervals.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.