Choosing Random Variable

This is My Code

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Root = character:WaitForChild("HumanoidRootPart")

local Animation1 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation1"))
local Animation2 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation2"))
local Animation3 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation3"))


local ChosenAnimation = --Random animation

I want it to choose a random one of the animations
and set it to Chosen Animation

LargeHotDogs13

1 Like
local animations = {} 

for _, child in pairs(script:GetChildren()) do --loop in case some of the children aren't animations
	if child:IsA("Animation") then
		table.insert(animations, child)
	end
end

local randomIndex = math.random(1, #animations)
local chosen = animations[randomIndex]

print(chosen)
3 Likes