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

Why isn't = working?

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

✓ Accepted answer

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

2 comments

0

Thanks for the help, and for the addition info too.

0

No problem, good luck in the future!

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

2 comments

0

Thank you so much

0

np

= is for assigning values, you are trying to compare 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!

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