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

Did I use my ifs, return end, and elses right? Did I end my code correctly?

Asked by 8 years ago

This is the main part I have a question on. Did I correctly use my ifs and elses?

01script.Parent.Touched:connect(function(hit)
02    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
03 
04 
05 
06 
07if hit.Parent.Parent:findFirstChild("Humanoid") then
08    if game.ServerStorage.DoesArena1Have2Players.Value == 2
09        then
10    return end
11 
12 
13else
14    if game.ServerStorage.DoesArena1Have2Players.Value <= 1
15        then
16 
17        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1
01debounce = false
02 
03script.Parent.Touched:connect(function(hit)
04    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
05 
06 
07 
08 
09if hit.Parent.Parent:findFirstChild("Humanoid") then
10    if game.ServerStorage.DoesArena1Have2Players.Value == 2
11        then
12    return end
13 
14 
15else
View all 39 lines...

Did I correctly end my code?

0
Also, Please note I am not done with the code. I just added the ifs and else today :P Relampago1204 73 — 8y
0
If you want to be a programmer, you should try your code first and make sure it works. Operation_Meme 890 — 8y
1
Also, one more thing, make sure you tab your code properly. It helps us read it. Operation_Meme 890 — 8y
0
Thanks :D Relampago1204 73 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

I fixed your indenting and fix your code, when using "else" it always goes before the end of the if function. NOT TESTED

1script.Parent.Touched:connect(function(hit)
2    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
3 
4if hit.Parent.Parent:findFirstChild("Humanoid") then
5    if game.ServerStorage.DoesArena1Have2Players.Value == 2 then
6        return
7    elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then
8        game.ServerStorage.DoesArena1Have2Players.Value =     game.ServerStorage.DoesArena1Have2Players.Value+1
9    end
01debounce = false
02 
03script.Parent.Touched:connect(function(hit)
04Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
05if hit.Parent.Parent:findFirstChild("Humanoid") then
06    if game.ServerStorage.DoesArena1Have2Players.Value == 2 then
07        return
08    elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then
09        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1
10    end
11    if debounce == true then
12        return
13    end
14    debounce = true
15    Char = hit.Parent
View all 25 lines...
Ad

Answer this question