Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I use these events with coroutines correctly?

Asked by
TomsGames 225 Moderation Voter
10 years ago
    local killed = coroutine.create(function()
        print("Killed coroutine called")
        if script:FindFirstChild("Killed").Value == true then
            print("ending game")
            endgame("dead")
        end
    end)
    local timer = coroutine.create(function()
        for i = 0, 60, 1 do
            wait(1)
        end
        endgame("time")
    end)
    coroutine.resume(timer)
    script:FindFirstChild("Killed").Changed:connect(function()
        if script:FindFirstChild("Killed").Value == true then
            coroutine.resume(killed)
        end
    end)
end

function endgame(status)
    coroutine.yield(killed)
    coroutine.yield(timer)

This is a small portion of the script, don't worry too much about the ends.

Basically the script is supposed to listen for the variable "Killed" to turn true or until the time runs out, then it stops the other coroutine and carries on with the rest of the script.

What is wrong?

Answer this question