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

Part stops at a certain point?

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)

4 comments

0

use tweenservice

0

oh ok

0

or lerp the cframe

0

Or you could just use a >= lol

1 answer

✓ Accepted answer

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"

1 comment

0

oh I didn't think of that! Thank you very much!

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