i’m trying to load animation to skinned mesh and make it an npc but
the animation is either weird or won’t work at all
i tried to use the animate script from roblox, i tried to find an animated mesh npc in toolbox for reference, i also tried to make animation script myself
local function playAnimation(animationid)
local anim = Instance.new("Animation")
anim.AnimationId = animationid
animtrack = animator:LoadAnimation(anim)
animtrack:Play()
end
playAnimation(walk)
playAnimation(idle)
but nothing worked… and i have no idea why
can someone please explain me how to load an animation to a skinned mesh?
Like, detecting the Humanoid’s State Type of when your NPC is walking or staying idle
Could you try this…?
local function playAnimation(animationid)
local anim = Instance.new("Animation")
anim.AnimationId = animationid
animtrack = animator:LoadAnimation(anim)
animtrack:Play()
end
print("Does the script even work ._.")
local Humanoid = script.Parent:WaitForChild("Humanoid")
print(Humanoid)
print("???")
Humanoid.StateChanged:Connect(function(Old, NewState)
print("State Changed")
if NewState == Enum.HumanoidStateType.Running then
print("NPC is walking")
playAnimation(walk)
else
print("NPC is still")
playAnimation(idle)
end
end)
oh, i found out the issue, i accidently put it under a loop lol so it didn’t reach that code, but the animation still has some issues, it still always playing the run animation ;-;
local animtrack = nil
local animator = script.Parent.Humanoid.Animator
local Humanoid = script.Parent:WaitForChild("Humanoid")
local function playAnimation(animation)
animtrack = animator:LoadAnimation(script[animation])
animtrack:Play()
end
local function stop()
if animtrack then
animtrack:Stop()
end
end
Humanoid.StateChanged:Connect(function(Old, NewState)
if NewState == Enum.HumanoidStateType.Running then
stop()
print("NPC is walking")
playAnimation("walk")
else
stop()
print("NPC is still")
playAnimation("idle")
end
end)
the problem is, statechanged not firing always when state changed