Plugin reload w/ TestService

You can reload plugins via script WITHOUT RUN MODE:

local ts=game:GetService('TestService')
ts.Timeout=1/0
ts.AutoRuns=false

local hotrun=Instance.new'Script'
function _G.reload()
	ts:Done()	
	hotrun:Destroy()
	hotrun=Instance.new'Script'
	hotrun.Name='hotrun'
	hotrun.Source=[[
print'im new!!!'
local t=os.clock()
coroutine.wrap(function()
	while wait()do
		print(t)
	end
end)()

coroutine.yield()--try commenting me while keeping the wrap above. This is necessary or else all tests will be considered finished and code in non main thread will be killed
]]
	hotrun.Parent=ts
	coroutine.wrap(ts.Run)(ts)
end

If you put that in command bar and then call _G.reload() however many times you wish, you’ll see it stops the previous script’s output and starts spamming a new timestamp each time.

Combining this with return function wrapping, we can reload plugins ;D

The only downside is seeing some TestService output that unfortunately cannot be disabled :confused:

If you use TestService for cool things, please share them!

Can’t this be done with the relatively new plugin debugging feature?

1 Like

Not via script :wink:
This TestService method is very useful for me personally because I use a ~5 loc plugin that just requires a modulescript in my game which loads the edit context of my framework, so I can make changes and test them immediately

Edit: I think the use case I said above would work if I preferred switching from _G.reload() to the UI roblox provides (have not yet tried their UI), but I also have another command _G.execute() which basically reloads and then requires a module script which I like to write code in sometimes instead of the one line command bar, and I think the Debug UI workflow would add an extra step to that.