I have a block, there is a value inside of it called AirValue. AirValue's value slowly increases and resets back to 0. This script is supposed to make the block white, it does not do that though! here is the script
repeat wait(0.5) if script.Parent.Parent.Parent.AirValue.Value < 10 then script.Parent.BrickColor = "White" elseif script.Parent.Parent.Parent.AirValue.Value > 10 then script.Parent.BrickColor = "Bright blue" end until 9 + 10 == 21
Please help!!! Thank you!
You need to create a BrickColor object for it.
You can use BrickColor.new
to perform this
repeat wait(0.5) if script.Parent.Parent.Parent.AirValue.Value < 10 then script.Parent.BrickColor = BrickColor.new("Institutional White") elseif script.Parent.Parent.Parent.AirValue.Value > 10 then script.Parent.BrickColor = BrickColor.new("Bright blue") end until 9 + 10 == 21
BrickColor properties expect BrickColor values, not Strings, which you are trying to give.
Change "White"
to BrickColor.new("White")
and the same for "Bright blue"
.
Additionally, all of the ValueObjects have a Changed
event that fires when the value is changed to something different, so this code can be written more efficiently:
local air = script.Parent.Parent.Parent.AirValue air.Changed:connect(function() if air.Value < 10 then script.Parent.BrickColor = BrickColor.new("White") else -- no need to specific the other half of this set. script.Parent.BrickColor = BrickColor.new("Bright blue") end end)
As a side note: you can use the true
and false
literals:
9 + 10 == 21
always evaluates to false
, so you can just write that in instead of wasting the interpreter's time.