Crrustyy
(boblox_man)
#1
Hi! I have successfully scripted a script, where when a player activates a tool and clicks, an animation plays. It works GREAT!
However, however I was wondering how to play random animations, so it is different every time they click.
Here’s the script:
script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
Animation:Play()
end)
end)
script.Parent.Unequipped:Connect(function()
animation:Destroy()
end)
That’s the script! Just need some help in finding out how to play random animations!
Many thanks!
7 Likes
Create a folder with the animations you have then use math.random
local animationsFolder = game.Workspace.Folder:GetChildren()
script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
local randomAnimation = animationsFolder[math.random(1, #animationsFolder)]
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(randomAnimation)
end)
end)
script.Parent.Unequipped:Connect(function()
randomAnimation:Destroy()
end)
I hope I helped you 
14 Likes
Crrustyy
(boblox_man)
#3
It doesn’t seem to be working. Hmm I have typed it correctly, but nothing happens.
Do you see errors in the output?
Also make sure you changed from game.Workspace.Folder to the place of your folder
Crrustyy
(boblox_man)
#6
I have done so.
There’s nothing in the output about the animation.
However, there is a yellow line under
Can you make a screenshot with the script?
Crrustyy
(boblox_man)
#8
I have solved it I Think! Needed to add randomAnimation:Play()
And remove the local before randomAnimation
Crrustyy
(boblox_man)
#9
Nope, never mind. Doesn’t work.