The Breakdown
There are two different types of else statements. elseif and else. Both being extremely useful when it comes to scripting.
ELSEIF
elseif is used for whenever you need to ask, "Well, if they don't have this, do they have this instead?"
An example would be
local a = 5
if a == 6 then
print("A = 6!")
elseif a == 5 then
print("A = 5!")
end
The script above would make A equal 5, then ask, "Does A equal 6?", the if statement would return false, in other words, A does not equal 6. With the elseif added it asks another question, "Does a = 5?" The elseif statement would be true, resulting in a print of A = 5! You can have as many elseifs as you want in an if statement.
ELSE
When using an else, it will go ahead and ask the if statement, "Is what you're asking true?" If the if statement returns false, then the code underneath the line of else will run until it hits an end. You can only have one else in an if statement.
An example script would be:
local a = 5
if a == 6 then
print('A = 6!')
else
print('A does not equal 6!')
end
Your script would be:
local part = script.Parent
local db = true
local myVar = game.Workspace.Part.SurfaceGui.Test
part.Touched:connect(function(hit)
local hat = hit.Parent:FindFirstChild("SilverthornAntlers")
local human = hit.Parent:FindFirstChild("Humanoid")
if human and hat then
if db = true then
db = false
myVar.Text = ("HOW DARE YOU WEAR THAT WRETCHED HAT!?")
wait(4)
myVar.Text = ("YOU WILL BE SMITED BY MY WRATH!")
wait(4)
myVar.Text = ("DIE!!")
wait(2)
human:TakeDamage(human.MaxHealth)
wait(5)
db = true
elseif db = false
myVar.Text = "You're good to go!"
db = true
end
end
end
If you did not understand this, then please leave a comment! If you did, then please accept my answer! =)
3 comments
You don't need the () around strings, by the way
Please accept my answer.
This may not be important but, if, else, and elseif are not functions. They are conditional statements.