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

How can I make a brick move?

So I need help I have a script that perfectly works but ITS TOO LONG! Any way to make it short?

Here:

FloodWater = game.Workspace.FloodWater
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)
FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
wait(0.2)

2 answers

✓ Accepted answer

For Loops!


An easy way to do this, is to count the times "FloorWater" is CFramed on the Y-axis. In the example, you did 7, so start out like this:

for i = 1, 7 do

end

In there, all you do is put in you CFrame line.

This is what it should look like:

for i = 1, 7 do
	FloodWater.CFrame = FloodWater.CFrame + Vector3.new(0,2,0)
	wait(0.2)
end

That will eliminate all of those lines. On line 1, the 1 means how many times it runs in one iteration. If that 1 was 2, it would take (~)4 iterations to run. The 7 means how many times that code repeats. So if you have that "FloodWater" CFrame 2 studs every .2 seconds x number of times, x would go there (x would be a number).


Any questions, let me know!

In this case, you can use a for loop.

FloodWater=game.Workspace.FloodWater
for i=1,7 do
	FloodWater.CFrame=FloodWater.CFrame+Vector3.new(0,2,0)
	wait(0.2)
end

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