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

Why doesn't this script make the brick change to white when AirValue is less than 10?

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!

2 comments

0

yogi, I would also suggest you read my answer. It is good practice to avoid using loops, such as this, unless you absolutely need them.

0

I am sorry, i haven't run into ANY problems using this way of repeating, in any of my games, thanks though!

2 answers

✓ Accepted answer

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

1 comment

1

thank you, i forgot about the BrickColor.new part! XD

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.

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