Sound.SoundID = shows up as Expected 'then'

Hello, I am just going to pop this here. I have no idea what is going wrong but I will explain what I want to do. I am trying to make something that will detect when a soundID is a certain soundID, then it will change a TextButton to the text I have set it. Please help, thanks.


You are using = instead of == in the if statement. == checks if something is equal to something else, and = assigns a variable.


You need to use 2 set of values


if 2 + 3 == 5 then
	print("Two plus three is five")

you can only let > or < alone but for equal its with ==
you can also do ~= mean if its everything but not this

For more information read this:

1 Like

for any statements that detect if something is true or not, you will always have to use == because just one = would mean that you set the value.
To summarize:
one equal sign is setting a value
two equal signs are used for if statements

Not necessarily. You can check for a truthy value just by passing the variable. The point is that anything between if and then will get evaluated to a boolean (false and nil are false, everything else is true). Relational operators, such as ==, help you refine that condition.

Some reading material if you’re interested:

So next time I would have to explain better right? Or maybe change a bit of the wording.

Not quite. Everything you said was correct except for that first bit; == is not needed to check for truthy values, but it’s ideal if you need to handle strict equality. For example:

if yes then
if not yes then
if yes == true then
if yes == false then
if yes == nil then

These five examples are different.

  • First one: This will check is yes is truthy. The condition will pass for anything that isn’t either nil or false, as those will both evaluate to false.

  • Second one: not is negation, so it checks if yes is falsy. This means that nil and false will pass, but anything truthy will not.

  • Third one: This will check if yes is explicitly true. That means that only true will pass and anything else will be regarded as false, thus not passing (numbers, strings, false, nil, so on).

  • Fourth one: Same as above, but for false. Anything else (including nil) will be truthy for this and will not pass the conditional check.

  • Fifth one: Same as above, but for nil. Anything else (including false) will be truthy for this and will not pass the conditional check.