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

How would I make a part that moves up and down all the time?

How would I make a part that moves up and down all the time?

Let's say I want a part to move up until the Y-position == 10 and then move it down again to Y-position == 0 then up again... etc

I have tried to do this, but I was unable to.

Please note: I am not asking for any one to make the script for me, just how I would do it.

2 answers

✓ Accepted answer

Alrighty, there are 2 ways of doing this, im gonna explain both for your knowledge

First, we get the part, and create 2 for loops

movingPart = script.Parent

for i = 1, 10 do 

end

wait()

for i = 1, 10 do

end

The for loop will count from 1 to 10, which we can then use to increase and decrease the position We will now add a while loop (so this gets repeated until said so) and we will add the moving position of the part

movingPart = script.Parent

while wait(1) do
for i = 1, 10 do 
	movingPart.Position = Vector3.new(0,0 + i,0) -- We add i to this, which increases the y value
wait(0.09)
end

wait()

for i = 1, 10 do
	movingPart.Position = Vector3.new(0,0 - i,0)-- We take away i from this, which increases the y value
wait(0.09)
end
end

Now, we will do it the much more efficient way. It is more efficient because if you move the part, it still goes up and down, whereas if we use the method above, you would have to change the position every time the parts position is moved


local movingPart = script.Parent -- we get the part

while wait(1) do --wait a second before running the code again
	for I=1,10 do -- we create a for loop, like before
		movingPart.CFrame=brick.CFrame+Vector3.new(0,1,0)-- We use CFrame to increase the 		height.
		wait() --wait a fraction of a millisecond, or else it doesn't appear as a sliding brick.
	end --end the "for" loop

	wait()

	for I=1,10 do --This section is pretty much just a repeat.
		movingPart.CFrame=brick.CFrame+Vector3.new(0,-1,0)-- We use CFrame to decrease the 		height.
		wait()
	end
end 

I hope this helped increase your understanding of CFraming and positioning!

Ok, if you don't want a script.

You would use theeCFrame property, or lerp

1 comment

0

lol the other guy forgot lerp

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