#my task.spawn wont run. It used to run but now it doesnt

1 messages · Page 1 of 1 (latest)

foggy flower
#

i cant figured out why. AI feels like it is yapping random stuff which makes no sense and doesnt align with proper functions of the code

#

lemme send the code

#

    local RunnersAreDead = false

    task.spawn(function()
        print ("Working")
        while true do 
            task.wait(0.5)
            for player, data in pairs(activePlayersData) do
                if data.role == "Runner" and data.hasDied == true then
                    RunnersAreDead = true
                end
            end
            if RunnersAreDead then
                statusUpdate:FireAllClients("All the runners died. Tagger wins!")
                endRoundEarly()
                return
            end
        end
    end)

    task.spawn(function()
        print ("Working x2")
        for _, player in ipairs(activePlayersList) do
            if player.Character then
                local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
                if humanoid then
                    if RunnersAreDead then return end
                    humanoid.Died:Connect(function()
                        print ("Working x2")
                        if activePlayersData[player] then
                            activePlayersData[player].deathCount += 1
                            activePlayersData[player].hasDied = true
                            if activePlayersData[player].role == "Tagger" and activePlayersData[player].hasDied == true then
                                statusUpdate:FireAllClients("The tagger has died! Round ended.")
                                endRoundEarly()
                                if roundHasEnded then return end
                            end
                        end
                    end)
                end
            end
        end
    end)```
#

the tables are defined correctly so they are not the problem

#

neither endroundearly() function

#

the problem? task.spawn doesnt run at all

#

it doesnt even print "working"

crystal cipher
#

try printing something and see if it works before task.spawn that way we can tell that its actually going through the code like

print("test print")
-- working, will now run task.spawn functions:
task.spawn(function()
 -- code
end)
task.spawn(function()
 -- code
end)
#

@foggy flower

foggy flower
#

@crystal cipher i urm reordered my code and it works now-

#

doesnt task.spawn run regardless of code arrangement

#

i thought it is async, it runs immediately after the code is executed regardless of arrangement n being read top to bottom

crystal cipher
# foggy flower doesnt task.spawn run regardless of code arrangement

depends if something is yielding before the task.spawn then that will run first and go through all of it before task.spawn

Ex.

while true do
  print("random loop")
  task.wait(1)
end

task.spawn(function()
 -- this will not run
end)

BUT if u put the task.spawn function first then both will run:

task.spawn(function()
 -- this will RUN
end)

while true do -- this aswell
  print("random loop")
  task.wait(1)
end
velvet valve
foggy flower
#

and a loop too

#

for loop

crystal cipher
#

unless u placed it at the very top

#

where it will run first