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

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

Asked by 9 years ago

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!

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. adark 5487 — 9y
0
I am sorry, i haven't run into ANY problems using this way of repeating, in any of my games, thanks though! yogipanda123 120 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

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
thank you, i forgot about the BrickColor.new part! XD yogipanda123 120 — 9y
Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

Answer this question