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

roblox if statement not working, how can i use the "if" correctly?

Asked by 2 years ago

here is the code:

local a = script.Parent.Parent.acik.a.Transparency
local b = script.Parent.Parent.acik.b.Transparency
local c = script.Parent.Parent.acik.c.Transparency
local d = script.Parent.Parent.acik.d.Transparency
function onclick(click)
    if a and b and c and d == 0 then
        script.Sound:Play()
        wait(3.963)
        script.Sound2:Play()
        script.Parent.Beacon.Beam.Enabled = true        
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onclick)

?

0
is there any errors theking66hayday 841 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

the if statement isn't working because you're just checking if a and b and c exist, then you're checking if d is equal to 0, I think what you're trying to do is check if every letter is equal to 0, so you have to check individually for every single one of the variables, that's how you use it, like this:

local a = script.Parent.Parent.acik.a.Transparency
local b = script.Parent.Parent.acik.b.Transparency
local c = script.Parent.Parent.acik.c.Transparency
local d = script.Parent.Parent.acik.d.Transparency
function onclick(click)
    if a == 0 and b == 0 and c == 0 and d == 0 then
        script.Sound:Play()
        wait(3.963)
        script.Sound2:Play()
        script.Parent.Beacon.Beam.Enabled = true        
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onclick)
Ad
Log in to vote
0
Answered by 2 years ago

This is a weird one. I had the same thing happen to me. After 3 ands it glitches. For example

if a and b and c then
    print("s")
end

but you can just do it a bit weirder but it works

 if a  == 0 then
 if b  == 0 then
 if c  == 0 then
 if d  == 0 then
        script.Sound:Play()
        wait(3.963)
        script.Sound2:Play()
        script.Parent.Beacon.Beam.Enabled = true
end
end
end  
end

Also. Use tab instead of spacebar for the spaces behind the script. For god's sake.

Log in to vote
0
Answered by 2 years ago

thank guys

Answer this question