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

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

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?

4 comments

0

Also, Please note I am not done with the code. I just added the ifs and else today :P

0

If you want to be a programmer, you should try your code first and make sure it works.

1

Also, one more thing, make sure you tab your code properly. It helps us read it.

0

Thanks :D

1 answer

✓ Accepted answer

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)

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