It moves all of a sudden to another position but I want it to move slowly in the y axis
garagedoor = script.Parent.Parent wait(5) x = garagedoor.Position.X y = garagedoor.Position.Y z = garagedoor.Position.Z while true do garagedoor.Position = Vector3.new(x,y + 0.05,z) wait(1) end
It's because you don't increment y, do this instead:
garagedoor = script.Parent.Parent wait(5) x = garagedoor.Position.X y = garagedoor.Position.Y z = garagedoor.Position.Z while true do y = y + 0.05 garagedoor.Position = Vector3.new(x,y,z) wait(1) end
Although if you know the position you want the part to end in, you can use the tween service, which is way smoother and has some easing styles too (sort of like animations), I can help you with it as it might be a bit confusing to understand. If you want that, tell me in the comments!
Try this:
garagedoor = script.Parent.Parent wait(5) x = garagedoor.Position.X z = garagedoor.Position.Z while true do local y = garagedoor.Position.Y garagedoor.Position = Vector3.new(x, y + 0.01 ,z) wait(0.01) end
So the problem with your script was that you were adding 0.05 to y
, but y
never changed because you stored the garagedoor's original position in y
, not it's current position.
So let's say y
was 10. Then every time the loop went through, the new position of the garagedoor would be 10.05. Then the next loop it'd still be 10.05, and the next one it'd be 10.05..... you see the problem? y
is always going to be 10, so that means we're going to have to change y
to it's current position, not it's original position.
For this I put y
in the loop, so it's always going to be the garage door's current position, so if it is 10.05, then the next time it would be 10.1, then 10.15...
I also changed the values slightly. The smoother you want the brick to move, the less time you should put in the wait()
, (0.01 is the smallest). The slower you want to brick to move the less you add to y
.
You can always change these values to your liking, it's whatever you want the brick to move.