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

How would I write this statement multiple times?

Asked by 5 years ago

I would like this code to repeat multiple times. How do I do that without having to copy and paste it 20 times?

lift.Position = lift.Position + Vector3.new(0,-1,0)
    wait(0.1)

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago

Use a while true loop. Example:

while true do
    lift.Position = lift.Position + Vector3.new(0,-1,0)
    wait(0.1)
end

-This will repeat it forever, but if you need to repeat it e.g 20 times, use a for loop. example:

for i = 1, 20 do
    lift.Position = lift.Position + Vector3.new(0,-1,0)
    wait(0.1)
end

Read about the loops here

Hope this helps!

1
Thank you so much! mecatno22 4 — 5y
0
And I see in your BIO you are trying to learn how to script. For the basics, you can read this: https://scriptinghelpers.org/guides/lua-quick-start-guide , and if you are interested in events, this is a good site too: https://developer.roblox.com/ (there are not only events, try it) Miniller 562 — 5y
1
Oh, thanks! I didn't know about the lua quick start guide :) mecatno22 4 — 5y
Ad

Answer this question