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

What wrong with this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
while true do
    wait(0.01)
    for i=1,2 do
        wait(0.1)
    if script.Parent.Control.Value == 1 then

    script.Parent.Test.Mesh.Offset = (1,0,4.2)

    end
end

l don't know what wrong

0
NO VOTE DOWN IT,I want to know 7785543 2 — 10y
0
Your question was probably downvoted because it's asked poorly. You haven't described what you're trying to do or in what way the script is currently wrong -- this is not an example of a Good Question: https://scriptinghelpers.org/help/how-post-good-questions-answers BlueTaslem 18071 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Tab and space your script properly. This doesn't affect how the program runs, but it makes it much easier to understand and read, as well as makes it look much more attractive visually:

while true do
    wait(0.01)
    for i=1,2 do
        wait(0.1)
        if script.Parent.Control.Value == 1 then
            script.Parent.Test.Mesh.Offset = (1,0,4.2)
        end
    end

We can see a problem. The while do on the first line has no matching end (see how the last lines of this program are floating away from the left column?)

In addition to seeing this ourselves, Lua will tell you this. You just have to read the output.

input:8: 'end' expected (to close 'while' at line 1) near <eof>

while true do
    wait(0.01)
    for i=1,2 do
        wait(0.1)
        if script.Parent.Control.Value == 1 then
            script.Parent.Test.Mesh.Offset = (1,0,4.2)
        end
    end
end

There's another problem, though. The output will also tell us about that.

input:6: ')' expected near ','

Offset is a Vector3, so when we assign it, we have to use a new Vector3 value:

            script.Parent.Test.Mesh.Offset = Vector3.new(1,0,4.2)

Your script now looks like this:

while true do
    wait(0.01)
    for i=1,2 do
        wait(0.1)
        if script.Parent.Control.Value == 1 then
            script.Parent.Test.Mesh.Offset = Vector3.new(1,0,4.2)
        end
    end
end

This will work. But look: you aren't using i anywhere in this, and you're only repeating that loop twice. So your code is the same as this:

while true do
    wait(0.01)
    wait(0.1)
    if script.Parent.Control.Value == 1 then
        script.Parent.Test.Mesh.Offset = Vector3.new(1,0,4.2)
    end
    wait(0.1)
    if script.Parent.Control.Value == 1 then
        script.Parent.Test.Mesh.Offset = Vector3.new(1,0,4.2)
    end
end

Since wait(0.01) wait(0.1) will essentially be wait(0.1), there's no reason to not use the simpler

while true do
    wait(0.1)
    if script.Parent.Control.Value == 1 then
        script.Parent.Test.Mesh.Offset = Vector3.new(1,0,4.2)
    end
end
0
The i is what? 7785543 2 — 10y
Ad

Answer this question