How I Set A Variable? (am new at lua)

Question:
i was trying to do a simple variable system. But i don’t know how to set my variable! I already tried “setVar()” but it was invalid, am new at coding in Lua.

local MyVariable 
if MyVariable == 9
  then
print("var NOT 10")
else if MyVariable == 10
    then
   print("var IS 10")
  end
end

don’t know lau at all but according to https://www.lua.org/pil/4.2.html

you can just do

local MyVariable = "hello";

@EduardoTubePV
Fixed:

local MyVariable = 10 -- Assign this!
if MyVariable == 9 then -- Keep your if-thens clean
    print("var NOT 10")
else if MyVariable == 10 then
    print("var IS 10")
end
PS: (If this solves your problem, mark it as the solution)
4 Likes

good attempt but still not done properly

local MyVariable = 10 
if MyVariable == 10 then
    print("MyVariable is 10")
else
    print("MyVariable is not 10")
end

Yes it is. @lightdefusion was just making sure the code was true to the original that @EduardoTubePV provided us with.

2 Likes

Be kind and respectful. Be kind to all members and leave the community better than when you first logged on. We will not tolerate any form of bullying, hate speech, or harassment.

4 Likes

She has 47 solutions…

He/She had to say something because of YOUR actions!

So? Sounds like you just don’t want staff or mods seeing your behavior!

It seems like you are the one who was off-topic!

A good bit of us doesn’t even use Discord! And what would you even report people for?

We can discuss this further in a PM if you would like. :smiley:

Why are you being so hostile to people that are just trying to help you?

Maybe if you are so upset, you should stop being mentally online and go to Burger King, the working conditions there are great I hear! I know a guy who could hook you up :wink: His name is John from BK! @FlameGrillin

4 Likes

@PapayaDude See the little “L3” next to the profile picture?
image image image image image

That means that this person has been here long enough and been helpful enough to earn it all without ever getting in trouble. The Trust Level 3s will support each other and not tolerate your harsh statements towards them.

I’m pretty sure you’re the only one that’s going to get in trouble here.

5 Likes

For that matter, some of us aren’t that high, but we still do our best to help out and support y’all.

6 Likes

Hey also with the help that you have been given. If you are using python, instead of doing

if MyVariable == 9
  then
print("var NOT 10")
else if MyVariable == 10
    then

I would suggest doing

if MyVariable == 9
  then
print("var NOT 10")
elif MyVariable == 10
    then

The elif is like another IF statement but its a way to use many in one area

(Ounce again you might be doing something different so this might not help)

They are not? They are using lua (look at title)

1 Like

@dragonhunter1 I actually use Roblox daily and their coding language is also in Lua, so using if/else statements are no different than JavaScript if/else statements.

So, using what I’ve learned from Roblox and JavaScript, you can use the following code:

local myVariable = 10
if myVariable == 10 then
print("myVariable is 10")
else
print("myVariable is not 10")
end

Im pretty sure Roblox uses Luau. It’s derived from Lua 5.1.
From Roblox:

3 Likes

Ok, thanks for the additional info, while I was reviewing scripts in Roblox Studio they were in Lua and not Luau, it’s possible that Lua is the language for scripts on objects, but luau is the language for scripting, guess Roblox is just as simple as it is!

Which means some Lua probably still runs in it.

1 Like

this is legit what I posted but it got deleted

Your post isn’t deleted, although a few of your other ones are flagged.

oh so where do the posts go then?

I’m not sure what you mean. Your post hasn’t moved.