Repeat until not working correctly

why repeat until isnt working correctly?

when the possitions are same, “repeat” does not stop

	repeat
		local lock = workspace.buyukkapi.engel.Position
		local kontrol = workspace.engeltestkontrol.Position
		workspace.buyukkapi.engel.Position = workspace.buyukkapi.engel.Position - Vector3.new(0,0,0.25)
		workspace.buyukkapi.disli.ust.Orientation =workspace.buyukkapi.disli.ust.Orientation - Vector3.new(0,0,1)
		workspace.buyukkapi.disli.alt.Orientation =workspace.buyukkapi.disli.alt.Orientation + Vector3.new(0,0,1)
		wait(0.01)
		until lock == kontrol 
end)

just use while

local kontrol = workspace.engeltestkontrol.Position

while lock ~= kontrol.Position do
local lock = workspace.buyukkapi.engel.Position
		
		workspace.buyukkapi.engel.Position = workspace.buyukkapi.engel.Position - Vector3.new(0,0,0.25)
		workspace.buyukkapi.disli.ust.Orientation =workspace.buyukkapi.disli.ust.Orientation - Vector3.new(0,0,1)
		workspace.buyukkapi.disli.alt.Orientation =workspace.buyukkapi.disli.alt.Orientation + Vector3.new(0,0,1)
		wait(0.01)

end
	repeat
		local lock = workspace.buyukkapi.engel
		local kontrol = workspace.engeltestkontrol
		workspace.buyukkapi.engel.Position = workspace.buyukkapi.engel.Position - Vector3.new(0,0,0.25)
		workspace.buyukkapi.disli.ust.Orientation =workspace.buyukkapi.disli.ust.Orientation - Vector3.new(0,0,1)
		workspace.buyukkapi.disli.alt.Orientation =workspace.buyukkapi.disli.alt.Orientation + Vector3.new(0,0,1)
		wait(0.01)
	until lock.Position == kontrol.Position 

This should work

image
well… whats now?

robloxapp-20221112-0014021.wmv (685.1 KB)
not working

My guess as to the problem is that the positions never do equal one another, either because the underlying math is off or because positions can be unprecise by nature. If you’re just interested in code that works, the following should function granted all the variables/information given are accurate:

repeat
	local lock = workspace.buyukkapi.engel.Position
	local kontrol = workspace.engeltestkontrol.Position
	workspace.buyukkapi.engel.Position = workspace.buyukkapi.engel.Position - Vector3.new(0,0,0.25)
	workspace.buyukkapi.disli.ust.Orientation =workspace.buyukkapi.disli.ust.Orientation - Vector3.new(0,0,1)
	workspace.buyukkapi.disli.alt.Orientation =workspace.buyukkapi.disli.alt.Orientation + Vector3.new(0,0,1)
	wait(0.01)
until (lock-kontrol).Magnitude <= 0.6

Additionally, There’s a few things I’d like to note here:

  • Firstly, you’re storing the variables before the movement and wait function, so it would always overshoot by at least one loop if it did function correctly. (if elaboration is needed let me know)

  • You can use the -= and += Compound Assignment operators as replacements for ust.Orientation = ust.Orientation - Vector3.new(0,0,1) and .alt.Orientation = .alt.Orientation + Vector3.new(0,0,1) respectively. (ex: ust.Orientation += Vector3.new(0,0,1) )

  • TweenService is a much simpler, and better, way of achieving what you’re wanting; you can look into it at your own convenience.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.