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

How can I end this if statement while keeping another?

I know this will be easy but I want to get help. Basically I have this function(well stuff inside a function) here. It works completely but I am unsure on how to end one if statement while keeping another going.

if #_G.getTeam(game.Teams.Survivors) == 0 then	-- I want to keep this running	
			if first_infected.StarterGear.Revolver ~= nil then --I want to end this.
				first_infected.StarterGear.Revolver:Destroy()-- end here
				_G.infected()
					game.Workspace.Field1.Parent = game.Lighting
					wait(3)
					game.Lighting.Field1.Parent = game.Workspace

So basically where can I put the end to end the second if statement? Do I make sense. Thanks!

1 answer

✓ Accepted answer

You can by ending the code with an 'end', let you show you an example (With a different script);

local Numbers = 5 --This is what we're going to use
if Numbers == 5 then --This is our first 'if' statement
print("Five! :D") --This will print, well, 'Five! :D'
Numbers = 4 --Then this'll change Numbers to 4
if not Numbers == 5 then --If it isn't equal to five
print("Not equal to five. :c") --This'll print 'Not equal to five. :c'
else --Elseif it is
print("Nope :c") --It'll print 'Nope :c'
end --This ends the second 'if' statement, or ends the second 'if' coding
else --Elseif it isn't
print("Nope. :c") --It'll print 'Nope :c'
end --This ends the first 'if' statement, or ends the first 'if' coding

If I didn't explain good enough, just let me know and I'll try and explain it better. :) (Sorry, tired today, so sorry if I did corrections, or didn't explain too well) Hope this helped!

4 comments

0

Well explained. So I +1 but before I accept how can I apply that to my script?

0

Oh, then, for lines 8-10, you do something like 'end', next line your coding for the first, then for the last another 'end', the first end that is applied ends the code for the second 'if' statement, you can do more code after that, and do the same for the next end. Hope this helped! :)

0

Edited: to end that part, just put an 'end' after line 3. :)

0

You ought to indent your code so that it is more readable and so that you don't have to explain which end ends which if statement.

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