Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an NPC loop-play an animation?

Asked by 5 years ago

Hi! I'm a beginner scripter so I don't know how to script well, I tried making this but it doesn't work.

local anim = "AnAnimation"

while true do
anim:Play()
wait (0.99)
wait (0.99)
wait (0.99)
end

Any help would be helpful, thankiew! :3

0
Why are you using wait like that? WideSteal321 773 — 5y
0
wait(2.97) WideSteal321 773 — 5y
0
make the animation Loop cherrythetree 130 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Run from a (Server) Script

local animation = script.Parent
animation.AnimationId = "rbxassetid://0"
local model = workspace:WaitForChild("Model")
local animPlayer = model.Humanoid:LoadAnimation(animation)

while true do
    if script.Parent.TurnOff.Value == false then
        animPlayer:Play()
        wait(2)
    else
        wait()
    end
end

Notes

  1. Line 1: Make sure "script.Parent" is an Animation within ServerScriptService

  2. Line 2: Set this to the id number of the animation (you MUST own it) If you set this value on the animation itself in Studio, you can also just remove this line.

  3. Line 3: Set "Model" to the name of the NPC Model

  4. Line 4: Change this location (workspace.Model.Humanoid) to the NPC you want to animate

  5. Line 7: This is a BoolValue named "TurnOff" that when set to true will end the animation, it is parented under the Animation

  6. Line 9: The number in the wait(#) should be the amount of time the animation runs for (default of 2)

Explanation: You cannot just play an Animation, it must be loaded into the NPC and played from an Animation Track, which is automatically made when you load the Animation into the Humanoid

1
(He used this for his answer) animation.AnimationId = "rbxassetid://0" WideSteal321 773 — 5y
0
i have a question, why not "game.Workspace. ---" instead of "workspace. ----" ? BuzzKillGT 33 — 5y
0
still confused.. BuzzKillGT 33 — 5y
1
@BuzzKill, you can write game.Workspace, its just that its quicker to use the single word workspace as its pre-defined by ROBLOX SerpentineKing 3885 — 5y
View all comments (2 more)
0
I put the animation ServerScriptService right? and the script's parent is the nimation right? and theres a bool value parented in the animation right? BuzzKillGT 33 — 5y
1
yep, also make sure the bool's name matches the one in the script (animation under ServerScriptService, bool and script both under animation) SerpentineKing 3885 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Serpentine's answer will work, but there is a more efficient way to do it (in my opinion).

Like he said, you have to load it into a humanoid first and play the AnimationTrack object it creates.

local animation = Instance.new("Animation", script.Parent) -- create a new anim. object
animation.AnimationId = "rbxassetid://507766388" -- roblox idle anim
local model = workspace:WaitForChild("Dummy")
local AT = model.Humanoid:LoadAnimation(animation) -- load anim

while true do
    AT:Play()
    At.Stopped:wait() -- wait for track to stop playing, then play again
end

It utilizes the .Stopped event of the AnimationTrack, which waits for the animation to stop before proceeding.

0
at line 08 use AT not At WideSteal321 773 — 5y

Answer this question