Hello me and my friend have been working on a script that plays any amount of animations i can make and play them all randomly after each on finishes
we havent gotten it to work so im looking for help
here is the script
local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild('Humanoid')
local animations = {"1", "2", "3", "4"}
animation = Instance.new("Animation", script.Parent.Parent.Parent)
animation.AnimationID = "http://www.roblox.com/asset?id="..animations[math.random(1, #animations)]
AT = script.Parent.Parent.Parent.Humanoid:LoadAnimation(animation)
AT:Play()
Your animation IDs aren’t 1, 2, 3, and 4. You’d have to replace 1, 2, 3, and 4 with your actual IDs for the animations. Also, Humanoid:LoadAnimation is deprecated, use the new Animator.
You could just do… nextAnimationId = list[math.random(1, #list)]
But if the animations play a part in some sort of mechanic or skill (e.g. sword fighting), you may wish to add some consistency with sequential animation selection.
For example. If I click once, the first animation appears.
If I click again in a certain amount of time, the second animation appears, etc.
If I don’t click the mouse, the sequence resets so the first animation will appear next click.
The game S4 League used this to great affect with its sword mechanics, and something similar is seen in games like Counter Strike.
i just want a npc to play a random animation without and inputs like a click just on its own to play and animation and when it ends a different one plays
while true do
local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild('Humanoid')
local animations = {"1", "2", "3", "4"}
animation = Instance.new("Animation", script.Parent.Parent.Parent)
animation.AnimationID = "http://www.roblox.com/asset?id="..animations[math.random(1, #animations)]
AT = script.Parent.Parent.Parent.Humanoid:LoadAnimation(animation)
AT:Play()
AT.Stopped:Wait()
end
Wait for the Stopped event of the animation track. Also, please indent that if you use it: I can’t on mobile.
while true do
local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild('Humanoid')
local animations = {"6087331463", "6087338968", "6087342407", "6087344954"}
animation = Instance.new("Animation", script.Parent.Parent.Parent)
animation.AnimationID = "http://www.roblox.com/asset?id="..animations[math.random(1, #animations)]
AT = script.Parent.Parent.Parent.Humanoid:LoadAnimation(animation)
AT:Play()
AT.Stopped:Wait()
end
local npc = script.Parent
local humanoid = npc:FindFirstChild("Humanoid") -- I presume the NPC does have a Humanoid?
local animations = { 6087331463, 6087338968, 6087342407, 6087344954} -- Animation Ids are integers, not strings, so you don't need the " symbol.
local animator = humanoid:FindFirstChild("Animator",true) or Instance.new("Animator",humanoid) -- If the Animator object isn't found in the NPC, create a new one.
local animation = animator:FindFirstChild("Animation") or Instance.new("Animation",animator) -- Create an animation object for the Animator to use
--Main Loop
while humanoid.Health > 0 do -- Its not a good idea to create an infinite loop, so this loop can be stopped by killing the NPC.
local animationId = animations[math.random(1,#animations)] -- Get a random animation from the animations list
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationId
local animationTrack = animator:LoadAnimation(animation) -- The track represents what is currently playing.
animationTrack:Play() -- Play the track
animationTrack.Stopped:Wait() -- Wait until the track is Stoppped
wait(0.5)
print("Next Animation")
end