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

How can I make a brick move?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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!

Ad
Log in to vote
1
Answered by
AmiracIe 175
10 years ago

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

Answer this question