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

How do I include two "if" statements into a script?

Asked by 6 years ago

I tried basically to "nest" it by putting one if statement under another and I even tried the "and" operator, this is what I have so far:

--drgigabyte
local broomOne = script.Parent.Parent
local messOne = game.Workspace.floormesses.mess1
local messTwo = game.Workspace.floormesses.mess2
local messThree = game.Workspace.floormesses.mess3
local cashOne = game.Players.LocalPlayer.leaderstats.Money

script.Parent.Touched:connect(function(hit)
    if hit.Parent.Name == 'floormesses' then
        wait(.2)
        hit.Decal.Transparency = 1
        cashOne.Value = cashOne.Value + 10
        wait(.1)
        script.Disabled = true
        wait(6)
        script.Disabled = false
        end
end)

I'd like to have the second if be something like "If hit.Decal.Transparency > 1 then"

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

You should just be able to use the and operator to check both in the same line (nested if statements would work too). It is also important to check if hit has something called Decal inside before checking the transparency of the decal to avoid errors.

if hit.Parent.Name == 'floormesses' and hit:FindFirstChild("Decal") and hit.Decal.Transparency > 1 then

However, since the maximum transparency is 1 (1 is completely transparent), you might want to rethink this check. If you want to check if the decal is not transparent, it would be Transparency < 1.

Ad
Log in to vote
0
Answered by 6 years ago

If I understand what you're trying to do correctly, then wouldn't it be something like this?

--drgigabyte
local broomOne = script.Parent.Parent
local messOne = game.Workspace.floormesses.mess1
local messTwo = game.Workspace.floormesses.mess2
local messThree = game.Workspace.floormesses.mess3
local cashOne = game.Players.LocalPlayer.leaderstats.Money

script.Parent.Touched:connect(function(hit)
    if hit.Parent.Name == 'floormesses' then -- the first if statement
    if hit.Decal.Transparency > 1 then -- the second if statement
            wait(.2)
            hit.Decal.Transparency = 1
            cashOne.Value = cashOne.Value + 10
            wait(.1)
            script.Disabled = true
            wait(6)
         script.Disabled = false
    end -- end to the2nd one
    end -- end to the 1st one
end)
0
But I also believe you could just do if hit.Parent.Name == 'floormesses' and hit.Decal.Transparency > 1 then BouncingBrenda 44 — 6y

Answer this question