Coroutine does stop but RunService doesn't?

There is a RunService function in the coroutine function, but when I stop the coroutine, RunService doesn’t.

local co = coroutine.create(function()
    runservice.RenderStepped:Connect(function()
        print("Omg so fast!")
    end)
end)

When I :yield() it doesn’t stop printing “Omg so fast!”

Thanks for reading

Yielding doesn’t disconnect the RenderStepped event, you just yield the coroutine, the event still exists. You’d need to put the event in a variable and disconnect it from there

local event
local co = coroutine.create(function()
    event = runservice.RenderStepped:Connect(function()
        print("Omg so fast!")
    end)
end)

--Later when you go to yield the coroutine
event:Disconnect()
2 Likes

So functions/events in functions doesn’t stop even if bigger function disconnects? Thanks for help!

1 Like

They don’t, the only time that would happen is if you use Destroy on an instance one of its children has an event connected. But in the case of coroutines, yielding them will just yield the coroutine, so any events made in the coroutine will still run

1 Like

Thanks for info (Minimum character limit)

In ur script u r trying to yield a function which is connected to RunService. And RunService runs every frame.And runservice is not a function itself. it’s a service and has rbxscriptSignals. So if u try to yield then it wont yield the function.
bcoz the line " runservice.RenderStepped:Connect(function() end)" is not a function.It just listens to an event and connects the function.
that’s y u need to disconnect the signal to yield it.Just like @EmbatTheHybrid showed

1 Like