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
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
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
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