How would I yield until a function is done?

Hello, I made a Fade Wrapper in a ModuleScript which you only do Fade.FadeIn(Player) then it fades in.

But I want it to teleport the player when the fade is done. Now as I am calling it from another script using a ModuleScript and require how would I yield until the fade is done.

I could not find one, just about remoteevents etc.

Current Script:

if Map["Spawns"]:FindFirstChild(Spawn)

                        then

                            local TempFade = FadeService.FadeIn(Player)

                            -- Wait until fade is done and continue

ModuleScript:

local M = {}

function M.FadeOut(Player)

    local Gui = Player.PlayerGui:FindFirstChild("Fade")

    local Frame = Gui.Frame

    for i = 0,1,0.1 do

        Frame.BackgroundTransparency = i

        wait(0.01)

    end

end

function M.FadeIn(Player)

    local Gui = Player.PlayerGui:FindFirstChild("Fade")

    local Frame = Gui.Frame

    for i = 1,0,0.1 do

        Frame.BackgroundTransparency = i

        wait(0.01)

    end

end

return M

Thanks in advance.

Use bindables.

local bindable = Instance.new("BindableEvent")

local function a()
   -- code
   bindable:Fire()
end

bindable.Event:Wait() -- yield until the event fires

-- other code that needs to run after function has run once here,
-- otherwise if you need to wait for it to execute every time it is called,
-- use bindable.Event:Connect() to only run other code once you fire the event, which is when the function executes
3 Likes

Is bindable the only way to do it currently?