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

WHy isn't repeat working?

Here is my script so far but I am not sure of how to make it so the script repeats itself 4 times.

wait()
repeat(4)  P1. = Instance.new("part")
P1.Transparency = 0
P1.FormFactor = FormFactor.new = 2
P1.Size = Vector3.new("1,0.4,1")
P1.BrickColor = BrickColor.new("Bright Red")

Why isn't it reapeting four times?

4 comments

2

That is not the purpose of repeat.

2

Why down-vote this post. He didn't know how to use repeat correctly so he asked on a help website. There is no valid reason to say this was a bad post, even though it may have an obvious answer.

0

He down voted because there is something called a wiki that ROBLOX programmers use to get better at scripting. This person obviously did not pay any attention to the wiki

0

I do not know of the Wiki you speak of. Can you at least give me a link before making my reputation bad because I don't know how to use something?

2 answers

✓ Accepted answer

Lol, you used the repeat function WAY bad (no offense). Here's some help:

What you're looking for is a "for loop." For loops (in the way you need them) have an index (the number that changes), a goal number (the second number), and an optional increment (third number, default is 1).

Here's how the for loop you need works:

for index=1, 4 do
print"Hello world!"
end

This code prints "Hello world!" 4 times. You can also access the index:

for index=1, 4 do
print("This message was printed "..index.." times.")
end

(I think you can tell what this prints)

The index can be any string, like "b," "boba," "bobafett3544isthegreatestpersonever," etc.

All you need to do is remove the repeat(4), the wait(), and add a "for i=1, 4 do" at the beginning, and don't forget the "end."

If this is a good answer, please upvote!

If you have any questions, feel free to comment!

2 comments

0

Okay! This worked! I am really bad at scripting. I can't upvote because I answered someones question and it made a part fling stright up instead of forward and he downvoted it, Which I think is kind of unfair. Sorry

0

I'll upvote some of your stuff.

The easiest way to loop code four times is to use a numeric for loop:

wait()
for i = 1, 4 do
P1 = Instance.new("part") --"P1" not "P1."
P1.Transparency = 0
P1.FormFactor = FormFactor.new = 2
P1.Size = Vector3.new("1,0.4,1")
P1.BrickColor = BrickColor.new("Bright Red")
end

repeat requires a matching until line to complete the loop:

repeat
--code
until (conditional)

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