How can I yield a function within the same script?

How would I go about getting a function to call upon another function whenever it needs specific variables that could frequently change and cannot advance without being given said variables?

Preferably going about this without creating a loop or copy/pasting the same code over again.

Use a bindable event to create a pseudoyield. Here’s an example that you could work with:

local signal = Instance.new("BindableEvent")

local function abAfter()
    signal:Wait()
    -- code
end

local function abBefore()
    abAfter()
    -- Code
    signal:Fire()
end

abBefore()

BindableEvents are one way to do it. I also believe there is a coroutine method, but I haven’t worked well with coroutines. Since they aren’t object based (like a pseudoclass), I have a hard time using them.

4 Likes