Canceling a function in another function

Hello, devs! I had made a module script where it helps you to build your very own advanced dialogue system (like in those visual novels), It is almost done except for one feature, skipping. I still have no idea how I make the skipping as I still don’t know how to cancel a function that isn’t in that function. For ex:

local DialogueModule = {}

function DialogueModule.Typewriter(sT) -- (sT is a string word table)
  for i, v in pairs(sT) do
  
 for sIndex = 1, string.len(i), 1 do
  -- type writer effect etc etc
  wait(0.1)
 end
end

function DialogueModule.CancelEverything()
 -- some function cancelation thing
end

return DialogueModule

In that function, I want to cancel the function, but from another function (aka we cant use return as it only works for the function it is nested upon)

Usually to cancel a function, you’d have to make a thread with either task.spawn or something with coroutines and then you would have to use task.cancel. here is an example

function a()
	print("oh")
end

local thread = task.spawn(a)
task.cancel(thread)