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?
local clickdetector = script.Parent local part = workspace.Mark3 clickdetector.MouseClick:Connect(function() repeat wait(0) for i = 1, 1 do part.CFrame = part.CFrame * CFrame.new(0,0.1,0) end until part.Position.Y == workspace.Mark1.Position.Y 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"