How to make a LocalScript re-enable itself when its Disabled property changes

Yeah, we can use it for an localscript.

Coroutine did not worked for me too.

Make it separate scripts??? You can’t make it re-enable itself if it cant run anything.

I found a pretty disgusting way to achieve this using threads, it also takes destroying into consideration:

task.spawn(function()
	local clone = script:Clone() 
	local old_parent = script.Parent

	while task.wait(.1) do 
		if not script.Parent then
			local new = clone:Clone()
			new.Parent = old_parent 
			break
		elseif script.Disabled then 
			script.Disabled = false 
			break
		end
	end
end)
5 Likes

How long has this solution existed? I’m surprised I’m just now finding out about it.

another local script with the disabled script as its parent that waits on the .Changed event

script.Parent.Changed:Connect(function()
   print(script.Parent.Disabled)
end)

This solution is the one, it works surprisingly perfectly, and I’m surprised nobody’s ever shared it to the public, thank you so much.

1 Like

Just to make sure, this works pretty much the same with coroutines, right?