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?
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
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