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?
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?
== 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â
=
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.
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
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.
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
Ok, finally understood thanks for replying sorry if this took your time a bit longer have a great day
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
== 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