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

This if statement is not working when its running?

Asked by 7 years ago
Edited 7 years ago

when I run the script, it didn't work. The output said the "=" was an error

if Humanoid.Health = 50 then
    Head.BrickColor = BrickColor.new("Really red")  
end

1 answer

Log in to vote
2
Answered by 7 years ago

If statements make comparisons while the "=" sign is used to assign values. Instead you need to use the relational operator "==" which basically just means is equal to. It's also important to understand that the "==" operator compares two parameters and returns a boolean. So the correct code would be...

if Humanoid.Health == 50 then
   Head.BrickColor = BrickColor.new("Really red") 
end
0
Essentially, use "==" when reading values, and use "=" when changing them. cheetosrevenge 20 — 7y
Ad

Answer this question