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

What wrong with this script?

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

2 comments

0

NO VOTE DOWN IT,I want to know

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

1 answer

✓ Accepted answer

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

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

1 comment

0

The i is what?

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