Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 comment

1

its because you need == in a if statement

5 answers

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

1 comment

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 >=

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.

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

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.

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

3 comments

0

There's an error with the script in the first line, too, it should be Transparency == 1 then, not Transparency = 1 then.

0

you don't have to put things in the same line, that's only for other languages

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.