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

How do I change 'brickcolor' on value change?

Asked by 5 years ago

How do I change colour on value change?

local value = workspace.adsyg.Value --this is my value thing (number value)
local part = workspace.adsyg --this is the part colour i want to change

while true do
if value = 1 then
    part.Color = BrickColor.new("Lime green")
else
    part.Color = BrickColor.new("Bright red")
end
wait()
end

I also tried this script and it doesn't work

local value = workspace.adsyg.Value
local part = workspace.adsyg

while true do
if value = 1 then
    part.BrickColor.Lime green
else
    part.BrickColor.Bright red
end
wait()
end 

I am new to scripting so i don't know much. Thanks, Wolfornator

3 answers

Log in to vote
0
Answered by 5 years ago

I noticed that you have two objects inside of workspace called "adsyg". When you try to retrieve an object inside of a hierarchy it will return the first object of the name you give it. So if you try to do the whole "workspace.adsyg" twice, it will just return the same object twice.

In order to get both objects like you are trying to, you could either put the number value inside of the part or just change the name of the number value.

Another thing is on the first line when you declared value to be equal to workspace.adsyg.Value, since you're doing that any change to the number value after that will not be detected and the value variable will not change. This is because it's setting the variable to the value of the number value at that one time, it is probably in your interest to just get the number value object, and check the value when you need it.

Next, just a small syntax error on line 5 when comparing the value to a number. Just one equals sign "=" try's to set or declare something to be equal to another like a variable. What you want is a double equals sign "==" this compares two items together.

And finally just another small syntax error when setting the color of the parts. When setting the BrickColor it would be something like "part.BrickColor" and not "part.Color". When changing the color to a specific RGB value you can use "part.Color" with the Color3.fromRGB function.

Those were really the only problems I found with your code. Let me see if I can help fix it up for ya.

local part = workspace.adsyg --this is the part colour i want to change
local value = part.adsyg --this is my value thing (number value)

while true do
    local number = value.Value --the current value of the number value

    if number == 1 then
        part.BrickColor = BrickColor.new("Lime green")
    else
        part.BrickColor = BrickColor.new("Bright red")
    end

    wait()
end

All I'm assuming with this code is that you just put the number value object inside the part that changes color.

I hope I was helpful.

Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

Use value == 1, not = 1.

I'm not entirely sure the difference between between them both but == should work.

Maybe someone with more knowledge can explain.

if value == 1 then
0
"=" is an assignment operator while "==" is a relational operator. And it wouldn't really help his script much because it can't properly get the number value, and the value variable is set at the value the number value is at the time the script runs, so it never changes. CeramicTile 847 — 5y
0
Ah, thank you. pwx 1581 — 5y
Log in to vote
0
Answered by 5 years ago

Something like this will work way better.

local part = workspace.adsyg

part.Value.Changed:connect(function(value)
    part.Color = BrickColor.new(value == 1 and "Lime green" or "Bright red")
end)

it will only fire if the value gets changed and you dont need to do a while loop

0
https://gyazo.com/01bb26d9598511605ec06bfb60c71c89 It doesn't work properly. it does nothing Wolfornator 3 — 5y

Answer this question