I was trying to use spawn() to run 2 loops until i came into a problem.
the function that uses spawn() to be run runs but when it does the timer is already 0 despite the value being 60.
this suggests that the spawn() function runs very very early.
i tried putting the function in the spawn() but it didnt work.
here’s the code:
local function LockdownCountdown()
for i = BlastdoorTimer, 0, -1 do
ReactorScreen2.Screen.FacilityLockdownTimer.Timer.Text = "[ "..i.." ]"
end
workspace.SoundClose:Play()
end
spawn(LockdownCountdown)
for i = ExplosionTimer, 0, -1 do
ReactorScreen1.Screen.EstimatedTime.Timer.Text = "[ "..i.." ]"
wait(1)
end
Sounds["vine boom spam "]:Play()
spawn() and task.spawn() are used to fire a function or thread immediatley through the Engine Sheduler, they basically have the same functionallity as coroutines which Roblox recommends you look into before using task
The spawn() function is basically Deprecated, so you should be using task.spawn() for it to be faster and to impact less on performance, if you dont want it to fire immediatley, try task.defer().
Also spawn() and wait() are deprecated use task.spawn() for code that needs to run as soon as possible and task.defer() for everything else. For yielding use task.wait()
local function LockdownCountdown()
task.spawn(function()
for i = ExplosionTimer, 0, -1 do
ReactorScreen1.Screen.EstimatedTime.Timer.Text = "[ "..i.." ]"
task.wait(1)
end
Sounds["vine boom spam "]:Play()
end)
for i = BlastdoorTimer, 0, -1 do
ReactorScreen2.Screen.FacilityLockdownTimer.Timer.Text = "[ "..i.." ]"
task.wait(1)
end
workspace.SoundClose:Play()
end