Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I end this if statement while keeping another?

Asked by
wjs3456 90
10 years ago

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

Log in to vote
1
Answered by 10 years ago

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!

0
Well explained. So I +1 but before I accept how can I apply that to my script? wjs3456 90 — 10y
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! :) TheeDeathCaster 2368 — 10y
0
Edited: to end that part, just put an 'end' after line 3. :) TheeDeathCaster 2368 — 10y
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. blocco 185 — 10y
Ad

Answer this question