Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to do a pairs function with 2 variables?

To don't have a lot of load animation, I need a pairs function who search animation, this is my script:

anim = humanoid:GetPlayingAnimationTracks()

for i, track, track2 in pairs (anim) do

if track.Name == "Stand" and track2.Name == "Walk" then

track:Stop() 

track2:Play() 

end

end

And in output this said "tried to call a nil value with track2.Name" So how can I do, please?

2 answers

You're doing it incorrectly. Here's an example of how to do a in pairs loop.

for i, v in pairs(workspace:GetChildren()) do
    print(v.Name) -- prints everything in workspace
end

Edited code:

anim = humanoid:GetPlayingAnimationTracks()
for i, track in pairs(anim) do
    if track.Name == "Stand" then
        track:Stop()
    elseif track.Name == "Walk" then
        track:Play()
    end
end

Thanks, but this don't work because I want stop an animation then play an animation, but with this script, only the animation is stopped or is played.

This discussion is preserved as it was. New answers, comments, and votes are closed.