Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this script play four different animations in random order?

Asked by 6 years ago

So I have this script and it only plays two animations at the current time since that was all I have done, but say I wanted to play 3 or maybe four animations in a random order. How would I do this? Would I make a table of some sort?

local uis = game:GetService("UserInputService");
local plrs = game:GetService("Players");
local cooldown = false
local leftp = false

uis.InputBegan:Connect(function(obj, gp) 
    if obj.KeyCode == Enum.KeyCode.Q and not gp then 
    leftp = not(leftp) 
script.Damage.Disabled = false
if cooldown then
    return
end
cooldown = true
            if leftp then
                local anim1 = plrs.LocalPlayer.Character.Humanoid:LoadAnimation(script.LPunch)
                    anim1:Play()
            else 
                local anim2 = plrs.LocalPlayer.Character.Humanoid:LoadAnimation(script.RPunch)
                anim2:Play()
                end

            wait(0.5)
            cooldown = false
end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

Hey TheCrimsonVortex,

You are correct in saying that you would use a table to store the animations, and then play them by that. Let me demonstrate below how this may work, I will use my own original script that I am about to make.

Script

local plrs = game:GetService("Players");
local uis = game:GetService("UserInputService");
local animations = {script.RPunch, script.LPunch, script.RKick, script.LKick} -- The animations go in here. 

function make_it_happen(obj, gp)
    if obj.KeyCode == Enum.KeyCode.Q and not gp then
        --[[
            I will not be coding the basic things to make the animations happen, because you already know how to do that stuff, so I will just jump right into making a variable for the animations.
        --]]
        local anim = animations[math.random(#animations)]; -- This is the animation, you just load it. All I did was index a value from the animations table using a random number from 1 - the amount of values in the animations table.
    end
end

Well, I hope I helped and have a nice day!

~~ KingLoneCat

0
Thank you for the help. Conquesias 85 — 6y
0
Glad to help. KingLoneCat 2642 — 6y
Ad

Answer this question