How or when to know and use double equals or single ones like = and ==

Script errored when i say

if script.Parent.Parent = workspace then
-- yeah
end

but it doesnt error when

if script.Parent.Parent == workspace then
-- no comment
end

So when do I use these double equals == or = in a simple way?

2 Likes

== is to compare, generally used in an it statement. It will return true or false. = is to set something, like ‘local MyVariable = 1’, or ‘part.Parent = workspace’

4 Likes

= is used when you’re assigning a value to a variable.

Var = 5

Here you are assigning the value 5 to the variable Var

== is used when you want to check if a condition is true or false.

print(5 + 1 == 6) -- It would print true

print(1 + 1 == 3) -- It would print false

It will return true if the condition is true and false if the condition is false.

2 Likes

But in what condition, how does it know if i said in my post?
if script.parent.parent == workspace

Can you rephrase your question? I can’t make out what you just said

why it returns a false(error) if i said
if script.parent.parent = workspace?
but not
if script.parent.parent == workspace?
Yes i get how it will work with values but above, i dont quite get it :sweat_smile:

Comparison operators consists of:
==, >=, <=, >, <

And are usually used for comparing two things, meaning:
equal to, greater than or equal to, less than or equal to, greater than, less than

If a comparison is made, and it is true, the statement is true. Otherwise it’s false.
true == true > true, false == true > false

The average = is just for assigning variables.


Additionally, there’s a ~= relational operator, which is equivalent to not equal to.

More information:


You can’t use if a = b then, because it would error and not be possible.

3 Likes

I believe thats what he has said in his post?

Because that’s not how if-then statements work, you’re meant to give it a value, and if the value is truey then it will run the code inside it, if it is falsey then it won’t.

script.Parent.Parent = workspace

This line is not a value, it’s just a statement that changes a property. If you would do

print(script.Parent.Parent = workspace)

It would error (or print nil), because you’re trying to print something that isn’t a value. That would be like printing

print(qjfiwnifw)

It’s just printing random code, it doesn’t hold a value.

script.Parent.Parent == workspace

This line holds a value, true.

Doing

if script.Parent.Parent == workspace then

end

Is the same as doing

if true then

end

Because script.Parent.Parent == workspace returns the value true.

However, something like this:

if script.Parent.Parent = workspace then

end

Would pretty much be the same as

if wijdaniwfnwain then

end

It’s just random code that doesn’t hold a value.

Code that returns a value is called an expression

5 Likes

Ok, finally understood thanks for replying :slight_smile: sorry if this took your time a bit longer have a great day

1 Like

Well I would like to say"==" is equal to “is” and “=” means a parent, for example,

local example = false

if local example ==(is) false then
--example

local example2 = (parent) game.Workspace.Example


1 Like

== is asking what something is, like

if 1+1 == 2 then
      game:Destroy()
end

and = is telling something to change, like

game.Workspace.Noob.Transparency = 1