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

How do I make a script play multiple times on click?

Asked by
NecoBoss 194
10 years ago

Okay so I want a script to play 5 times but without copying the same script over and over. How do I this?

2 answers

Log in to vote
1
Answered by
User#2 0
10 years ago

Using a for loop you can run the same peice of code multiple times, while still only writing it once.

function DoSomething(Num)
    print(Num)
end

for i = 1, 5 do -- Start at i = 1 and increase i (by one) until it's more than 5
    DoSomething(i)
end

--- Output:
-- 1
-- 2
-- 3
-- 4
-- 5
Ad
Log in to vote
0
Answered by
Gamenew09 180
10 years ago

Just put what you want to execute in a function. Then call it 5 times either using a for loop or calling the function 5 times.

function doCode()
    --Do Stuff
end

for i = 1, 5 do
    doCode()
end
-- OR
doCode()
doCode()
doCode()
doCode()
doCode()
1
Initializing i at 0 will actually cause the loop to run 6 times. Ekkoh 635 — 10y
0
Thanks Ekkoh, I forgot... D: Gamenew09 180 — 10y

Answer this question