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

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

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)

?

1 comment

0

is there any errors

3 answers

✓ Accepted answer

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)

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.

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