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

Issue with for i < 10 do loop?

Asked by 8 years ago
i = 0

script.Parent.Touched(function()
    while i < 50 do
    m = Instance.new("Hint", workspace)
    m.Text = i
    wait(1)
    i = i + 1
end)

It error reads there is an unexpected symbol near ")" on line 9, but if I remove ) it breaks.

2 answers

Log in to vote
6
Answered by 8 years ago
i = 0

script.Parent.Touched:connect(function()--Your forgot to "connect" the function
    while i < 50 do
    m = Instance.new("Hint", workspace)
    m.Text = i
    wait(1)
    i = i + 1
end -- You need a second "end" for the while do loop
end)
Ad
Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
8 years ago

A "while" loop is its own code block. Therefore, end is needed after line 8.

i = 0

script.Parent.Touched:connect(function()
    while i < 50 do -- You could also do a "for" loop instead. It won't take up as much lines.
        local m = Instance.new("Hint", workspace)   -- You're going to end up making 50 messages.
        m.Text = i
        wait(1)
        i = i + 1
    end
end)
-- If you're curious about any of my comments, go ahead and tell me; I will happily explain it to you.
0
Thank you. Forgot destory XD WolfgangVonPrinz 0 — 8y

Answer this question