I'm a bit new to studio, and I am making a brick with a pointlight, and if the brightness is equal to 5, then it prints "hi".
What I don't know, is what is going on when I put "=" in there. This is the script...
if game.Workspace.wing.PointLight.Brightness = 5 then print 'hi' end
If I put > or < 5, then it works perfectly fine, but if I put =, it says "Workspace.Script:1: 'then' expected near '='".
What am I doing wrong?
What you are trying to use is a conditional operator
==
is the correct operator when you are trying to see if something is equal to
something else. Putting only one =
is for assigning a value to a variable.
Using your code:
if game.Workspace.wing.PointLight.Brightness == 5 then --I added the second '=' for you, also try to keep 'then' on the same line if possible. --It is not needed, but it keeps things cleaner. print 'hi' end
Let me know if you have any questions!
Note: For more details about this, visit this link http://wiki.roblox.com/index.php?title=Conditional_statement
To see if something is equal to another, you need to use two '='s, like this:
if game.Workspace.wing.PointLight.Brightness == 5 then print("Hi") end
=
is for assigning
values, you are trying tocompare
values, for this you need to add ==
if game.Workspace.wing.PointLight.Brightness == 5 -- If the brightness is equal to 5 then print hi. then print('hi') -- You need to add the brackets otherwise the print will not work end
Hope this helps!