How would i use the coroutine library?

I’ve been making a game, and i’ve been trying to make a raycast function that runs a callback when the raycast hits something, here is my code:
image
I’ve been trying to use the coroutine library for running the callback, but i don’t exactly know the right way to do it.

The Function type is:

type Function = () -> ()

Help will be appreciated.

It should work. All you need to do to run a coroutine is call it like a function. Here is some example code:

function MyCoolYieldingFunction(Parameters)
    task.wait(9999)
    print(Parameters)
end

local Arguments = 42

coroutine.wrap(MyCoolYieldingFunction)(Arguments)

If it isn’t working, try using strict typechecking to make sure you are passing in the correct types (put --!strict at the top of both the script in the picture you have shown, as well as the one that calls Tools:Raycast()).

1 Like

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