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

Why isn't = working?

Asked by 8 years ago

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?

3 answers

Log in to vote
2
Answered by
Necrorave 560 Moderation Voter
8 years ago

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

0
Thanks for the help, and for the addition info too. ItsTheELitist 29 — 8y
0
No problem, good luck in the future! Necrorave 560 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

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
0
Thank you so much ItsTheELitist 29 — 8y
0
np TheDeadlyPanther 2460 — 8y
Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
8 years ago

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

Answer this question