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?

script.Parent.Touched:connect(function(hit)
    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)




if hit.Parent.Parent:findFirstChild("Humanoid") then
    if game.ServerStorage.DoesArena1Have2Players.Value == 2
        then
    return end


else
    if game.ServerStorage.DoesArena1Have2Players.Value <= 1
        then

        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1



debounce = false

script.Parent.Touched:connect(function(hit)
    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)




if hit.Parent.Parent:findFirstChild("Humanoid") then
    if game.ServerStorage.DoesArena1Have2Players.Value == 2
        then
    return end


else
    if game.ServerStorage.DoesArena1Have2Players.Value <= 1
        then

        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1




if debounce == true then return end
    debounce = true
    Char = hit.Parent
    Char.Torso.CFrame = CFrame.new(game.Workspace.tele.Position + Vector3.new(0, 5, 0))
debounce = false
     m = Instance.new("Message", workspace)
    m.Text = "Get Ready to Fight!"
    wait(5)

    m:Destroy()

game.ReplicatedStorage["Sword"]:clone().Parent = Player2.Backpack

end
end
end)


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

script.Parent.Touched:connect(function(hit)
    Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)

if hit.Parent.Parent:findFirstChild("Humanoid") then
    if game.ServerStorage.DoesArena1Have2Players.Value == 2 then
        return
    elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then
        game.ServerStorage.DoesArena1Have2Players.Value =     game.ServerStorage.DoesArena1Have2Players.Value+1
    end

debounce = false script.Parent.Touched:connect(function(hit) Player2 = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent.Parent:findFirstChild("Humanoid") then if game.ServerStorage.DoesArena1Have2Players.Value == 2 then return elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1 end if debounce == true then return end debounce = true Char = hit.Parent Char.Torso.CFrame = CFrame.new(game.Workspace.tele.Position + Vector3.new(0, 5, 0)) debounce = false m = Instance.new("Message", workspace) m.Text = "Get Ready to Fight!" wait(5) m:Destroy() game.ReplicatedStorage["Sword"]:clone().Parent = Player2.Backpack end end)
Ad

Answer this question