Function still gets called even though there is a task.wait() before it

You can write your topic however you want, but you need to answer these questions:

  1. i want to make these functions fire after each wait

  2. the first three functions all fire at once, then the next four all fire at the correct interval.

  3. i tried adding debounce and it did nothing.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local debounce = false
local length
local function toSymbol(symbol)
	if not debounce then
		debounce = true
		length = (currentSymbol.Value - symbol)
		--if length > 39 then
		--	length = (currentSymbol.Value - symbol)
		--end

		local goal = {Value = chevrons[symbol]}

		local tween = TweenService:Create(ringrotation, TweenInfo.new(math.abs(length) * 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), goal)

		print("current symbol is ".. currentSymbol.Value)
		print("new symbol is ".. symbol)
		print("length is ".. length)
		print("------------------")

		tween:Play()
		currentSymbol.Value = symbol
		
		task.wait(0.2)
		debounce = false
	end
end

-- abydos = 15, 35, 27, 24, 30, 12

print("get ready")
task.wait(2)
print("mark")

toSymbol(15)
task.wait(length*0.5 + 2)
toSymbol(35)
task.wait(length*0.5 + 2)
toSymbol(27)
task.wait(length*0.5 + 2)
toSymbol(24)
task.wait(length*0.5 + 2)
toSymbol(30)
task.wait(length*0.5 + 2)
toSymbol(12)
task.wait(length*0.5 + 2)
toSymbol(2)

the waits are not the final product so dont complain, i’m just trying to test the function and im running into this issue idk why.

2 Likes

I’m not sure what this (The Number/IntValue) starts out as. However, assuming it’s 0. What your doing is the length is -15 for the first function. Since the length is -15, when we calculate the task.wait() it’s -15*0.5 + 2 which is -5.5. We can’t wait negative seconds so it just waits the shortest amount, starting the next function

1 Like

The starting value is 1, however later on I put a math.abs in there to make the number positive. This still didn’t fix it.

So I removed the “length” and replace it with the number it should be.

It worked.

What I can conclude from this is that every task.wait() within a script gets the time instantly when the script starts, so once it gets down to the task.wait(), even if the value has since changed, it still will use the one from the start of the script. This seems a very odd decision, as we cannot have dynamic task.wait() times, the number must always be predefined.

So the fix for me it seems to use to use actual numbers instead of a value that changes as the “length” progresses.

1 Like

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