When the character is idle then do a Instance.new(“Animation”) then the script will choose which animation id to the Animation Instance then after the Anim length the current anim stop then Anim Instance get new random animid again.
I dont know how to do that, currently new to script. Please give me some suggest. Thanks for reading
So you would need to make sure the animation id can be accessed possibly by using api or just trial and error (there is probably another way but I haven’t got time to test right now) then you can do math.random(1,9) for the length the animation id or you could math.random(1,animation id length)
Then you would store those in a variable and make a new Animation with
Instance.new(‘Animation’) and setting the Animation id to the number.
i knew about math.random but after the Anim Length does the Animation Instance get a new animid again? I havent try to not tick “Looped” on the anim , but if i do that will the animInstane get a new id or it still play the old one
Inside a local script under StarterCharacterScripts
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animations = Character:WaitForChild("Animations") -- Wherever your list of animation instances are.
local AnimationsArray = { }
for i, Animation in ipairs(Animations:GetChildren()) do
local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
table.insert(AnimationsArray, AnimationTrack)
end
function PlayRandomAnimation()
local RandomAnimation = math.random(1, #AnimationsArray)
local AnimationTrack = AnimationsArray[RandomAnimation]
AnimationTrack:Play()
AnimationTrack.Stopped:Wait()
PlayRandomAnimation()
end
PlayRandomAnimation()