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

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

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)

6 comments

0

Any errors?

0

Also make sure your if statements are embedded in each other because it looks like two are just next to each other

0

What do you mean?

0

you need multiple ends, one end for every if

0

For shortening your code, you can do "if humanoid and not firecheck and not smokecheck then" instead of what you did.

2 answers

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.

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!

2 comments

0

this may not help your problem but its how to have 3 ifs..

0

ifs can be used an unlimited amount of times too!

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