Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to prevent errors in a looping round script with a giant pcall?

If, in some bizarre case, you have a looping round script and it breaks, your entire game is on freeze. Forever! In that case, could you possibly wrap said round script in a giant pcall as follows?

function mainRoundSequence()
	while wait() do
		-- intermission
		wait(10)
		-- load map
		wait(5)
		-- load characters
		wait(30)
		-- round over
		wait(5)
		-- articulate the round stats, start over.
	end
end

while wait(1) do
	success, err = pcall(function()
		mainRoundSequence()
	end)

	if err then print(err) end
end

Again, would this script theoretically work to make your script "break-proof"? Thanks in advance.

3 comments

1

couldnt it still hang on the error forever just continually restarting? i guess it depends what the issue is.

0

yeah what DinozCreates said, most errors won't fix themselves, it is best that they "freeze" it

1

You shouldn't call wait in the condition because it is hacky. It only works because it abuses the fact that numbers are truthy values, and wait returns a number.

1 answer

✓ Accepted answer

While you could, you do not need to do this, and this does not make your scripts 100% break proof. pcall only catches runtime errors, so if you have syntax errors do not expect pcall to stop those. Syntax errors are what prevent your code from compiling in the first place. You should only wrap the bits that cause you problems in a pcall, and then fix them once you realise the error. And please do not call wait in your loop's condition.

1 comment

0

Thanks, and I don't see why I shouldn't place a wait in my loop's condition

This discussion is preserved as it was. New answers, comments, and votes are closed.