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

How are you able to have three "if then" statements in a row?

Asked by
SirPaco 66
6 years ago

I am trying to create a script that burns you when you touch a part but I have three "if end" statements in a row which is why I believe it is not working.

    if humanoid then
    if not firecheck then
        if not smokecheck then

Please try to fix this for me and explain what I did wrong so I know what to do for next time.

local lava = script.Parent
local fire = Instance.new("Fire")
local smoke = Instance.new("Smoke")
lava.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
local firecheck = hit.Parent.Torso:FindFistChild("Fire")
local smokecheck = hit.Parent.Torso:FindFistChild("Smoke")
    if humanoid then
    if not firecheck then
        if not smokecheck then
    end
    fire.Parent = hit.Parent.Torso
    smoke.Opacity = 0.1
    smoke.Parent = hit.Parent.Torso
    for steps = 1, 10, 1 do
    humanoid:TakeDamage(5)
    wait(1)
    end
    fire:Destroy()
    smoke:Destroy()
end
end
end)

0
Any errors? Draebrewop 114 — 6y
0
Also make sure your if statements are embedded in each other because it looks like two are just next to each other Draebrewop 114 — 6y
0
What do you mean? SirPaco 66 — 6y
1
You should indent your code correctly. http://wiki.roblox.com/index.php?title=Lua_Style_Guide#Whitespace_Rules BlueTaslem 18071 — 6y
View all comments (2 more)
0
you need multiple ends, one end for every if abnotaddable 920 — 6y
0
For shortening your code, you can do "if humanoid and not firecheck and not smokecheck then" instead of what you did. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

First and foremost: Scripts using "Torso" will ONLY work in R6 mode. Just a heads up.

I see a couple problems here. First of all, you should move your creation of the fire and the smoke to after your "if" checks. The way it currently is, it would only give one player fire and smoke and then would not do it again. If you move them, it will check if the character has them, and once it finds out they do not, it will make them.

It appears that the main reason your script is not working is a misplaced "end".

This should fix it

local lava = script.Parent
lava.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
local torso = humanoid.Parent:FindFirstChild("Torso")
local smokecheck = hit.Parent.Torso:FindFistChild("Smoke")
    if humanoid then
         if torso then
              local firecheck = torso:FindFirstChild("Fire")
                   if not firecheck then
                   local fire = Instance.new("Fire", torso)
                   local smokecheck = torso:FindFirstChild("Smoke")
                        if not smokecheck then
                        local smoke = Instance.new("Smoke", torso)
                        fire.Parent = hit.Parent.Torso
                        smoke.Opacity = 0.1
                        smoke.Parent = hit.Parent.Torso
                             for steps = 1, 10, 1 do
                                  humanoid:TakeDamage(5)
                                  wait(1)
                             end
                       fire:Destroy()
                       smoke:Destroy()
     end
          end
               end
                    end
end)

I apologize for any spacing that's off. I had to do this without a tab button. Hopefully this works for you.

Ad
Log in to vote
0
Answered by 6 years ago

Having 3 ifs is quite easy to make look here

if humanoid then
elseif not firecheck then
elseif not smokecheck then

elseif's will work similar to else's but they can be used an unlimited ammount of times and kinda work like if's!

0
this may not help your problem but its how to have 3 ifs.. outlook1234567890 115 — 6y
0
ifs can be used an unlimited amount of times too! hiimgoodpack 2009 — 6y

Answer this question