How would I select a random object?

I have a script that I need to select a random animation to play every 5-10 seconds, how do I select an animation at random from a list of animation within a folder?

This could be easily solved with a google search, please look this stuff up before making a post.

That said here’s basically how you would do it:

     local anims = folder:GetChildren()
     return anims[math.random(1,#anims)]
1 Like

When you start the game in studio, you can find your characterModel in the workspace and there is a internal script written by ROBLOX which show you how to use ‘Weight’ to control the animations.

local function getRandomItem(itemsToPickFrom)
    local itemsLength = #itemsToPickFrom
    return itemsToPickFrom[math.random(1, itemsLength)]

--How to use:
-- local animations = {script.Parent.Jump, script.Parent.Walk}
-- local chosenAnimation = getRandomItem(animations)
1 Like