Task.wait() does not respect script.Disabled and always resumes

Will this fix also affect the original wait() and its identified inconsistent behaviour?

This change will only affect the task library

4 Likes

while this is still not fixed, I suggest using coroutine instead, result from my test task.wait() seems to respect coroutine.close(), but keep in mind RBXScriptConnection does not respect coroutine.close().

Potentially resolved?

Delayed threads (threads scheduled with task.delay or task.wait) will no longer be resumed in disabled scripts

https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-514

2 Likes

Yes. I’ll follow-up on this thread once it’s live

5 Likes

Thanks for fixing this. I’ve had to use code like this:

local function EnableThreads()
	CC = true
end
local function KillThreads()
	CC = false
end
local function ScriptUpdated()
	if (script.Disabled == true) then
		KillThreads()
	elseif (script.Disabled == false) then
		EnableThreads()
	end
end
local ScriptDestroyingConection:RBXScriptConnection;
local ScriptDisabledConnection:RBXScriptConnection;
local ActorDestroyingConnection:RBXScriptConnection;
local function GC()
	KillThreads()
	if (Actor ~= nil) and (Actor:IsA("Actor") == true) then
		Actor:Destroy()
	end
	if (ScriptDestroyingConection) then
		ScriptDestroyingConection:Disconnect()
	end
	if (ScriptDisabledConnection) then
		ScriptDisabledConnection:Disconnect()
	end
	if (ActorDestroyingConnection) then
		ActorDestroyingConnection:Disconnect()
	end
	script:Destroy()
end
ScriptDestroyingConection = script.Destroying:Connect(GC)
ScriptDisabledConnection = script.Changed:Connect(KillThreads)
ActorDestroyingConnection = Actor.Destroying:Connect(GC)
...
while (CC == true) and (task.wait()) do
...

The fix for this is now live.

23 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.