#my task.spawn wont run. It used to run but now it doesnt
1 messages · Page 1 of 1 (latest)
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"
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
ill have to reorder my code since task.spawn is placed below a countdown
@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
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
maybe something disables or destroys the script?
task spawn 1?
well at that case i might have placed it under a return statement
and a loop too
for loop
true, or something like
randomvalue.Changed:Wait()
or any other yielding functions will yield the code
unless u placed it at the very top
where it will run first