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
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