Animated NPC - Animation

Hi guys! I have been trying to make it for a while now, I want to make NPC, that could move with animation I did.
I have found only when you can press on the NPC, and the animation plays. But I would like it always to play without clicking on it!
Here is the script I used for the click play animation.

local NPC = script.Parent.Parent.Parent

local Plays = false
local humanoid = NPC:WaitForChild(“Humanoid”)

local Anim = Instance.new(“Animation”)

Anim.AnimationId = “rbxassetid://6161519819”
local AnimPlay = humanoid:LoadAnimation(Anim)

script.Parent.MouseClick:Connect(function()
if Plays == false then
AnimPlay:Play()
Plays = true
else
Plays = false
AnimPlay:Stop()
end
end)

Thank you!

3 Likes

if the animation is a loop you can just do it without the mouseclick but if it aint repeating you could put it in a while true loop or something

I would either use a while loop or simply just set Looped to true as shown below. Hope this solved your issue.

local NPC = script.Parent.Parent.Parent
local Humanoid = NPC:WaitForChild("Humanoid")

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6161519819"

local AnimationPlay = Humanoid:LoadAnimation(Animation)
AnimationPlay.Looped = true
AnimationPlay:Play()
2 Likes

Thank you! :grin: It really helped me.

1 Like