Couroutine returns 'nil'

I cant seem to fix it, it only returns ‘nil’

function shot()
	task.wait(0.2)
	SHOT  = false
	return "ye"
end
local co = coroutine.wrap(shot)
local s = co()
print(s)
1 Like

If the coroutine makes a function that returns “ye”, it must be “ye”, not nil.

1 Like

yea i dont understand what u mean by this lmao

You can simplify the code like this:

local co = coroutine.wrap(function()
    task.wait(0.2)
    SHOT = false --What even is "SHOT"?
    return "ye"
end)

print(co())

I still don’t know what the error is.

returns empty, shot is a variable

Do you have to use coroutines?
Can’t you use a simple function?

function shot()
	task.wait(0.2)
	SHOT  = false
	return "ye"
end

print(shot())

i trigger that function inside another function, so coroutine is needed

I think it’s because of the delay.
Is that needed?

local co = coroutine.wrap(function()
    --No delay.
    SHOT = false
    return "ye"
end)

print(co())

Hold on, imma try sum else to see if it works

I don’t have much experience with coroutines, though perhaps this may be of use to you?

Coroutines create a separate thread. Threads cannot speak to each other. You will be unable to return back to the main thread using this method. You need to develop a listener using another function, and call that instead of calling return. If you want to halt the main thread, then do not use a coroutine.

ye cool, i dont need coroutines no more found a better way