Slowing down a function Retrying Itself?

Hi,

How Would I slow down this function which retries itself it it doesn’t get the Correct Number?
It can fire really fast and cause lag, How would I do this?

Example:

NumberExample = function(x: number)
  local Number = math.random(1,100)
  if Number == x then
     print("Finished")
  else
     NumberExample(95)
  end
end)
NumberExample(95)

You can try this method:

local i = 0 --Add to top of script
NumberExample = function(x: number)
    local Number = math.random(1,100)
    if Number == x then
       print("Finished")
    else
        if i % 512 == 1 then task.wait() end
        i += 1
        NumberExample(x)
    end
end)

Doesn’t Appear to work, sorry…

Ah, i am an idiot, all i needed to add was a simple wait

NumberExample = function(x: number)
	local Number = math.random(1, 100); print(Number)
	if Number == x then
		print("Finished")
	else
		task.wait(.1)
		NumberExample(x)
	end
end
NumberExample(95)

Thanks for trying to help @SubtotalAnt8185

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