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

Using "if not" seems to get ignored and moves on to the next script?

Asked by 5 years ago
if not v.ZIndex == "-1"  then
                v.Visible = false

            end

When I put a "not" nothing changes, anyone know how to use not?

2 answers

Log in to vote
1
Answered by 5 years ago

The reason for this is because the GuiObject.ZIndex property holds an integer value, and you attempted to compare it to a string, which will return false. Simply make it -1 and it will be good from there.

Truthy values

In Lua, anything but false or nil is truthy. So numbers, strings and tables are all examples of truthy values. The boolean true itself is also truthy. If you print(not 5), that would print false, as you're inverting the "truthiness" of the number. So by you doing if not v.ZIndex == "-1" then, you're actually just saying if false == "-1" then. In order to fix this, you can wrap the v.ZIndex == -1 in brackets, or make your == an ~=.

if not (v.ZIndex == -1) then

----OR----
if v.ZIndex ~= -1 then
Ad
Log in to vote
1
Answered by
Aimarekin 345 Moderation Voter
5 years ago
Edited 5 years ago

not only works for booleans, not if the condition is not met.

Try this instead. ~= means not equal to.

I quit the "", because the ZIndez is a number, not a string.

if v.ZIndex ~= -1  then
    v.Visible = false
end

Hope it helps

0
Actually t can be if the condition is met. Read my answer. User#19524 175 — 5y
0
I have never got to accomñish that by using a not. Aimarekin 345 — 5y
0
accomplish* Aimarekin 345 — 5y

Answer this question