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

Workspace.Script:2: 'then' expected near '=' <== Why is this??

Asked by 5 years ago
Edited by BlueTaslem 5 years ago
if
game.Workspace.Part1.Transparency = 1 

then
    game.Workspace.Part2.Color = DarkGreen
end

I just started scripting in lua and just practicing some codes and this came up adn i do not know why this is wrong? (Trying to change the part2's color when part 1's transparency is at 1)

1
its because you need == in a if statement mattchew1010 396 — 5y

5 answers

Log in to vote
2
Answered by 5 years ago
if game.Workspace.Part1.Transperence == 1 then -- the error is the u use only 1 =.  == means is same as ~= means different as. and >= bigger and same. > only bigger as. <= smaller and same >only smaller as.

    game.Workspace.Part2.Color = BrickColor.DarkGreen()

end
0
use only 1 = if u give some thing a value like local hoi = hoi.value but with if then u almost need always 2 == or when u want to say its different ~= see 2 symbols only need 1 symbol if u say bigger then > or smaller then <, even when i say bigger then or is the same i need 2 symbols <= or >= User#27824 0 — 5y
Ad
Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
5 years ago

Your first problem: you're using = rather than == in the first line. When you check something, you use ==, and when you define a variable, you use =. Your second problem: you're setting the part's Color when you should be setting its BrickColor.

Fixed version:

if game.Workspace.Part1.Transparency == 1 then
    game.Workspace.Part2.BrickColor = BrickColor.new("Dark green")
end

Also, a tip: use workspace rather than game.Workspace. Just makes things a bit easier.

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You have to have two ==s because it signifies that the transparency is equal to 1. Also here's a re-written code if you want it

if game.Workspace.Part1.Transparency == 1 then
    game.Workspace.Part2.BrickColor = BrickColor.Green()
end
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Remember; you always need a double "equals" after an "if" or an "until" statement.

if game.workspace.part1.Transparency == 1 then
    game.workspace.part2.BrickColor = BrickColor.Green()
end

The way I remember it is to do a peace sign. You lift up your middle finger and your index finger. These two fingers mean the two "equals" you need to add in there.

Log in to vote
-2
Answered by 5 years ago
Edited 5 years ago

Your 'then' must be in the same line as 'if'. Here's your script:

if game.Workspace.Part1.Transparency = 1 then
    game.Workspace.Part2.Color = DarkGreen
end
0
There's an error with the script in the first line, too, it should be Transparency == 1 then, not Transparency = 1 then. mudathir2007 157 — 5y
0
you don't have to put things in the same line, that's only for other languages Elyzzia 1294 — 5y
0
While it *should* be for good style, Lua doesn't require it -- Lua doesn't care about how you indent/space your files. (Lua programmers, on the other hand, rightfully DO care, a lot) BlueTaslem 18071 — 5y

Answer this question