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

I have 3 animations for an npc, how do I make them play randomly and constantly with a 2 sec delay?

Asked by 5 years ago
local attacks = script:GetChildren()

for i,v  in pairs(attacks) do
    local chosenAttack = math.random(#attacks)
    script.Parent.Humanoid:LoadAnimation(chosenAttack):Play()
    --[[ this picks only 1 random attack, and plays it once. how do i make it randomly play the animations with a 2 second delay? ]]
end
0
Sorry, the script picks 3 animations, plays them all, but then it won't play any more animations. How do I make it do that? ChillTart 4 — 5y

1 answer

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

Simple fix! wait(x) x = Seconds (must be a real number.*)

  • Must be Positive, 0+, can have decimals, can't be a negative

What is wait? wait is a delay function, Whatever goes in () is in seconds.

Examples of wait wait(1) < waiting one second print(waited one second)

local attacks = script:GetChildren()

for i,v  in pairs(attacks) do
    local chosenAttack = math.random(#attacks)
wait(2) 
    script.Parent.Humanoid:LoadAnimation(chosenAttack):Play()
end
0
So I figured it out just now, and this works as well. ChillTart 4 — 5y
0
Aww okay. AlertShamrock 37 — 5y
Ad

Answer this question