Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the code not running correctly?

Asked by
Carvyy 15
10 years ago

Hi. I recently started to practice on my Lua books and I'm a very beginner scripter. I made the line of code below to see if I was getting the hang of statements, and I guess I really wasn't. I want it to change the color of "Door_1" if the equation is correct. I got an error message saying it expected a "= " near else which really confused me.

a = 5
b = 10
e = 15

if 
    a + b == e
    then print("Passcode Correct: Unlocking Door.")
    Game.Workspace.Door_1.BrickColor = Light Green
else 
    print("Passcode Incorrect: Door Locked.")
end

Again, I am a very beginner scripter and this may seem ridiculous to some of you, considering it's such an easy thing that I most likely messed up. I found it a better idea to come here, and as the advanced scripters rather than just going on Google and searching for a way to let me script run because we'll, I need to know what I did wrong just not correct it.

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
-- You aren't setting the values and you're using them at the top, so there's no reason not to make these vars local 

local a = 5
local b = 10
local e = 15

if a + b == e then
     -- I don't know if your formatting messed up?
    print("Passcode Correct: Unlocking Door.")
    game.Workspace.Door_1.BrickColor = BrickColor.new("Bright green")
    -- You didn't put BrickColor.new("string")
    -- Also there is no 'Light Green' or 'Light green'
else 
    print("Passcode Incorrect: Door Locked.")
end

0
Wow, thanks. I see that I really messed up on this. I'm gonna have to really review. Thanks Azarth. Carvyy 15 — 10y
0
Omg thanks I finally got it. Thanks so much. Carvyy 15 — 10y
Ad

Answer this question