How do you use coroutines?


Goal

I want to be able to put a coroutine into the running status then suspend it if I desire to.

Issue

Every time I run my function, it keeps saying it’s in a suspended function.

Script

local SignalListeners = {Timers = {}}
function Run(Hum)
	if not table.find(SignalListeners.Timers,Hum) then
		SignalListeners.Timers[Hum] = coroutine.create(function() wait(10) Hum:SetAttribute("Attacker"," ") end)
	end
	Hum:SetAttribute("Attacker",Item.Parent.Name)
	if coroutine.status(SignalListeners.Timers[Hum]) == "suspended" then
		--task.spawn(SignalListeners.Timers[Hum])
		coroutine.resume(SignalListeners.Timers[Hum])
		wait(.01)
		warn("Current State: "..coroutine.status(SignalListeners.Timers[Hum]))
	end
end

Here’s a post about coroutines which should help!

1 Like