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

GOTO Line Help?

Is there a GOTO command in ROBLOX? It would be very useful. If not is there any workarounds?

for i = 1, 30 do
	wait(1)
	if game.Players.NumPlayers < 2 then
		break
	end
end
if game.Players.NumPlayers < 2 then
	while true do
		if game.Players.NumPlayers > 1 then
			break
		end
		wait()
	end	
end

I'm making a script for my fighting game. And it is supposed to run a 30 second intermission. But if there is only one player left, it waits for a new player then restarts the intermission timer.

1 answer

No. Lua supports goto only from 5.2 beta versions and on; ROBLOX is stable 5.1.

It is a general consensus (though this is debated) that gotos are rarely what you want to use to solve a problem.


break (not "continue" -- Lua doesn't have continue -- mistake -- thank you TaslemGuy) act as a form of limited jumping.

Functions are a very powerful way to define routines.


If you specify a particular problem, we could describe a good solution (that doesn't need goto)


First, I would definitely simplify the second loop you have:

while game.Players.NumPlayers < 2 do
	wait()
end

I'm not exactly sure what you want to do. I don't see any particular point where you would want to act.

But speaking very generally, this is an architecture that might work for you:

local modes = {}

function modes.intermission()
	for i = 1, 30 do
		wait(1)
		if game.Players.NumPlayers < 2 then
			return "waitForPlayers"
			break
		end
	end
	return "playGame"
end

function modes.waitForPlayers()
	while game.Players.NumPlayers < 2 do
		wait()
	end
	return "intermission"
end

----

local mode = "intermission"
while true do
	mode = modes[mode]()
	wait()
end

Clever breaks and ifs would also work, but could get to be a mess with a larger script.

2 comments

0

I edited, please look

1

One note: Lua does not have a continue keyword.

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