Prevent inf loop hanging / :SetTimeout(5) doesnt work?

I am attempting to recreate a script by CrazyMan32 called “Live Reloading” but attempting to make it a plugin

Youtube Video

I have got it to work and execute the script live but if the user is writing a script at the time and begins to write a loop

while true do

end

apon finishing typing the loop studio instantly hangs (as it is an inf loop and the script ran it)

I have attempted to put the script execution in a separate thread but to no luck.
Also attempting to set the script timeout doesnt work (i believe it is broken?)

game:GetService("ScriptContext"):SetTimeout(5)

Also manually seting the script timeout doesnt work either is there any way to fix this
(other than not coding loops while the plugin is running)

Heres my script execution code (uses loadstring/pcalls)

local function update(scriptsource)
	if scriptsource ~= nil then
		local loaded, err = loadstring(scriptsource.Source)
		local success = (loaded ~= nil)
		if loaded then
			local script_thread =coroutine.create(function()
				game:GetService("ScriptContext"):SetTimeout(5)
				success, err = pcall(loaded)
			end)
			coroutine.resume(script_thread)
		end
		if not success then
			warn(err)
		end
	end
end

update(game.Workspace.Script)

GIF
Shows hanging ^

2 Likes

I would add a wait() no matter what. That could lag/crash.

1 Like

That isnt very possible as roblox’s auto complete does not automatically add a wait()

GIF

2 Likes

please watch the gif it shows that it hangs apon completing,
there is one work around by not using the auto complete and typing the end manually but i was wondering if there is a work around

2 Likes

I am not sure. Hopefully someone comes past and answers this.

1 Like

You can try doing

while wait() do

end
2 Likes

hmm alright thanks (i normally dont type loops like that so i didnt know it works)
ill use this as a work around for the time being thank you

2 Likes