I tried making a script where a part rises once clicked and it rises until a certain point, but when testing, it keeps rising on and on. Is there a way to make it stop once it is the same position on the y-axis?
01 | local clickdetector = script.Parent |
02 | local part = workspace.Mark 3 |
03 |
04 | clickdetector.MouseClick:Connect( function () |
05 | repeat |
06 | wait( 0 ) |
07 | for i = 1 , 1 do |
08 | part.CFrame = part.CFrame * CFrame.new( 0 , 0.1 , 0 ) |
09 | end |
10 | until part.Position.Y = = workspace.Mark 1. Position.Y |
11 | end ) |
There's no need for the for
loop because of your repeat
loop if you're just aiming to make part
move up. I also recommend using addition to move the part
upwards because multiplying any number by a decimal makes the product smaller.
Lastly, at the until
part of your repeat loop, if the position is off by even a little bit over, it won't stop the loop so I recommend changing the ==
to a >=
because >=
means "is bigger than or equal to"