In what kind of code should I put to "==" instead of "="

In what line of code should I use to == instead of = I forgot it what kind of code I think is a variable or function pls help me. Like this I hope I’m write:. Local hotdogs = 7. I think pls help

1 Like

In an, if statement, just using = is setting one value to another but saying == is comparing them.

For example:

local Cash = 10 -- Setting value

if Cash == 10 then -- comparing value
print("You have enough cash")
end
5 Likes

I’m not sure I understand your question, but you use “==” when checking if something is the same as something else, like in an if statement. For declaring variables you just use “=”

‘==’ are only used in if statements, use ‘=’ for variables and such.

Example:

local player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function()
     if player.Name == 'airsoft561' then
         print('Airsoft561 has joined the game!')
   end
end)
1 Like

That’s right, use == when you need to compare things.

So say I wanted to make a variable, you just use = so for example…

local teststring = "test"

Then if I wanted to compare this variable with someone I would use == so for example…

if teststring == "test" then
      print(testring)
end

All I can say is that you should only use == for if you are trying to define variables in an if statement for instance,
Y == 10
X == 5 if
X == 5 then
“Function”.
I’m a little new to scripting but definitely gotten better at it. That’s a quick example of when to use == in.

= means assigning a value

== means checking a value

2 Likes

That’s wrong. You don’t define a variable with “==”.

Y = 10
X = 5
if X == 5 then
 yourFunctionHere()
end
Y == 10
X == 5 
if X == 5 then
"Function"
end

Wouldn’t work.

You will use “=” when casting, “==, ~=, <=, >=” in statements, “: (Used to be =>)” when casting types

Thanks i mixed up the words a little…
Thanks for correcting me!

== is used for checking, while = is used for setting.

To be more specific == is done in expression evaluations. A true or false result.

You can also have fun with inline-expressions as well.

local Status = 0
print(Status == 0 and 'status is 0' or Status == 1 and 'status is 1')

That’s just some pseudo code, though.

== is used for checking while = is used for setting.

Here’s the script:

local Value  = 5

if Value == 5 then
    print("Value")
end

= is to set something
== is to compare something