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

Why doesn't this If statement run?

Am I using Or wrong? The map values change when a player clicks the GUI, I've tested and looked over the numbers, when it's 4 or 7 it wont turn indivisible. I don't get it...

--This one works:
while wait() do
if workspace.Map.Value ~= 6 then
	script.Parent.Visible = true
elseif workspace.Map.Value == 6 then
	workspace.Type.Value = 0
	script.Parent.Visible = false
end


--And yet this one doesn't work:
while wait() do
if workspace.Map.Value ~= 4 or workspace.Map.Value ~= 7 then--Why doesn't this work?
	script.Parent.Visible = true
elseif workspace.Map.Value == 4 or workspace.Map.Value == 7 then
	workspace.Type.Value = 0
	script.Parent.Visible = false
end

EDIT: Here's a perfect example http://wiki.roblox.com/index.php?title=Or_operator#Or Right below the Or operator it gives this example "if soul == true or food == true or try == true then" So how come this works? But yet I cant do the same with numbers?

2 comments

0

I don't understand what you are trying to do.

0

I dont get why lines 13 and 14 dont work when line 3 and 5 work. When I remove the Or, it works fine with 4, but I need 7 there as well.

2 answers

✓ Accepted answer

This is a logical error.

Consider this conditional more closely:

workspace.Map.Value ~= 4 or workspace.Map.Value ~= 7

If the Value is '4', the second half of that is true and thus the whole thing is true. If the Value is '7', the first half is true and the whole thing is true. Any other number, any both halves are true.

To fix this, change that or to an and, since you only want that if to be executed when the Value is neither '4' nor '7'.

Alternatively, I would probably write this code like this:

while wait() do
if workspace.Map.Value == 4 or workspace.Map.Value == 7 then
    script.Parent.Visible = false
    workspace.Type.Value = 0
else --not 4 or 7
    script.Parent.Visible = true
end

1 comment

0

Ugh, total brainfart. Thank you +1ed and accepted answer.

I don't know how both loops are working because you're missing an end for each one. Did an error not show up in the output or something?

while wait() do
	if workspace.Map.Value ~= 6 then
		script.Parent.Visible = true
	elseif workspace.Map.Value == 6 then
		workspace.Type.Value = 0
		script.Parent.Visible = false
	end
end

while wait() do
	if workspace.Map.Value ~= 4 or workspace.Map.Value ~= 7 then
		script.Parent.Visible = true
	elseif workspace.Map.Value == 4 or workspace.Map.Value == 7 then
		workspace.Type.Value = 0
		script.Parent.Visible = false
	end
end

5 comments

0

I'm not missing an End, you only need a End if you're using Else not Elseif

0

Read this, you do need an end when you use a while loop. http://wiki.roblox.com/index.php?title=In-Depth_Scripting_Guide#The_.27end.27_Statement

0

I do, they are even lines up, first end is for the If statement, which the elseif is in, the second end is for the loop.

0

I only say one end for each loop in your code, so I wouldn't have known.

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