How to use not. I am confused


if dna:WaitForChild(selected.."Owned").Value == true and not dna:WaitForChild("Equipped").Value == selected then

	script.Parent.Text = "Equip"

elseif dna:WaitForChild("Equipped").Value == selected.Value then
	script.Parent.Text = "Equipped"

elseif dna:WaitForChild(selected.."Owned").Value == false and not dna:WaitForChild("Equipped").Value == selected then
	script.Parent.Text = "Buy"
end
while wait() do
	selected = script.Parent.Parent.Parent:WaitForChild("ViewportFrame").View.Value
	if dna:WaitForChild(selected.."Owned").Value == true and not dna:WaitForChild("Equipped").Value == selected then

		script.Parent.Text = "Equip"

	elseif dna:WaitForChild("Equipped").Value == selected.Value then
		script.Parent.Text = "Equipped"

	elseif dna:WaitForChild(selected.."Owned").Value == false and not dna:WaitForChild("Equipped").Value == selected then
		script.Parent.Text = "Buy"
	end
	
	
end

This code doesn’t work for the things called not. How do I even use not. Basicly I want to make it so if dna:WaitForChild(“Equipped”).Value is not equal to selected

im pretty sure it means when something is false

local Bool = false
if not Bool then
print(“Bool is false”)
end

How do I do it for a string then. I am kinda confused

Not is actually pretty simple lol. It means the opposite of what it is. Here’s a code example

local number = 0
local x = 1

if x == (not number) then
print(“hello”)
end

All it basically means is if x is not equal to 0 then print. In this case, it prints hello.

While in Python and Ruby not x == y may work because not has lower precedence than == operator, it may not work in Lua because not has a higher precendence than the == operator so the left-hand side is calculator first.
Use the ~= operator to see if it doesn’t equal to something.

Thank you it works now :smiley:

Use ~= (not equal to) in this specific example.

Your condition is currently evaluated in this order:

  • The value of Equipped is obtained.
  • It is negated by the not, and therefore becomes true or false based on whether the value is truthy or not.
  • This Boolean is then compared using the == operator to your selected variable.
  • The condition fails every time unless selected is a Boolean that matches the first one.

not operations happen before comparison operations.

not dna:WaitForChild("Equipped").Value == selected
-- is the same as
(not dna:WaitForChild("Equipped").Value) == selected
not (dna:WaitForChild("Equipped").Value == selected)
-- is the same as
dna:WaitForChild("Equipped").Value ~= selected
1 Like

To add on to this topic, “not” is a simpler version of “~=” (not equal to).
“not” is also good for reversing conditions!

Example:

Part = nil

If Part then
    print("Part is not nil!")
end

If not Part then
    print("Part is nil")
end
1 Like