How can I script a NPC to do an animation?

Tried but still nothing in output and won’t work.

1 Like

Won’t work, nothing in output.

1 Like

Can you make sure that the NPC isn’t anchored?

2 Likes

You shouldn’t use the other code samples in this thread if the first one given doesn’t work. The first one will work if your setup is correct. If it doesn’t work for you, your rig isn’t set up right.

Check for:

  • Correctly indexing the Humanoid
  • Does the script actually run? Is it maybe disabled?
  • Is the rig anchored? (it shouldn’t be anchored)
4 Likes

Here are some suggestions,

Make sure that the animation belongs to you, if you are doing a group game, upload that game to that group.```
1 Like

Animation is in the group, game is in the group, and I am owner of the group but I cannot take the animation for some reason nor make it for sale by configuring it.

1 Like

You should try importing it using Moon Animation Suite plugin or ROBLOX Main one. After that export it again to your group.

1 Like

Are you trying to make so that the npc load the animation ingame?

1 Like

I am trying to make that NPC does the animation, what do you mean by him loading the animation?

1 Like

Loading basically makes the npc ingame shows the animation.

1 Like

Basically that.

1 Like

Hey sorry for being pushy but can you make sure that none of the parts in the NPC are anchored. It’s a pretty common problem in a lot of the “animation won’t play” threads.

2 Likes

For the humanoid,

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=(animation)"

-- Local variables
local animTrack = nil
local canPlay = script.Parent:findFirstChild("CanPlay")

function playShockAnim(Source)
    if canPlay then
        local playAnimation = game.(model).Character
        canPlay.Value = false
        animTrack = game.Destrioggok.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
        animTrack.KeyFrameReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
            if keyframeName == "end" then
                canPlay.Value = true
            end
        end)
        animTrack:Play() -- Start the animation
    end


end

script.Parent:WaitForChild("CanPlay").Changed:connect(playShockAnim)

What I did above is : I created a BoolValue to store the canplay ability. If the NPC touches the part , the BoolValue will transfer to the person or Humanoid that touched it.Then if the Canplay ability is true , the animation plays.

1 Like

Everything is anchored.

1 Like

Then unanchor them! Anchored parts won’t move.

1 Like

It shouldn’t be anchored! Only HumanoidRootPart has to be anchored. Everything else must be anchored to false!

1 Like

Note: the humanoid has to be unanchored.

1 Like

Now infinite yeld is possible

1 Like

Could you show us the whole output?

1 Like

Here’s a pretty solid suggestion:

Use the script that buildthomas suggested in the first reply, and this time make sure that none of the parts in the NPC are anchored.

1 Like