Problem with : Repeat Until

Hi ! I have a problem with the my script :confused:

while true do
local a = 0.1
script.Parent.Position = script.Parent.Position +,a,0)
a = a + 0.1
until a == 1
a = a - 0.1	
script.Parent.Position = script.Parent.Position -,a,0)
until a == 0.1

The purpose of this script is that the part that owns this script goes up and down infinitely. But the problem is that it goes up infinitely, and it never goes down… Why does it never go down?

try adding a wait(.1) at the end of the while script, and setting it until >= 1 rather than just 1. likewise for the counting down portion, only <= .1

I’ve had issues with repeat scripts in the past. They are hard to get working correctly.

1 Like

Floating point errors. Hence why it’s never a good idea to use == for looping double value.
Use >= 0.1 instead.

Btw, you can do

script.Parent.Position -=,a,0)

instead of

script.Parent.Position = script.Parent.Position -,a,0)