#Change Part Color Based On Variable

15 messages · Page 1 of 1 (latest)

whole snow
#

When activating a tool it decreases flashes by 1 and prints it (this worked alone) but when I added the part for changing the brickcolor the script broke and stopped doing anything. It should change the color of the part based on how much flashes you have left. This is my code (in a local script)

local flashes = 2
local chargepart = script.Parent:FindFirstChild("Charge")

tool.Activated:Connect(function()
    flashes -= 1
    print(flashes)
end)
coroutine.wrap(function()
    while true do
        if flashes == 2 then
            chargepart.BrickColor = BrickColor.new("Lime green")
        elseif flashes == 1 then
            chargepart.BrickColor = BrickColor.new("New Yeller")
        elseif flashes == 0 then
            chargepart.BrickColor = BrickColor.new("Really red")
        end
    end
end)
rancid cobalt
#

try this :

local colors = {
  [0] = BrickColor.new("Really red")
  [1] = BrickColor.new("New Yeller")
  [2] = BrickColor.new("Lime green")
}

local flashes = #colors
local tool = script.Parent
local chargepart = script.Parent:FindFirstChild("Charge")

tool.Activated:Connect(function()
    flashes -= 1

    local color = colors[flashes]
    if color then
      chargepart.BrickColor = color
    else
      flashes  = #colors
      chargepart.BrickColor = colors[flashes]
  end
end)

and dont do a while true loop without a wait in it

flint sigil
# rancid cobalt try this : ```lua local colors = { [0] = BrickColor.new("Really red") [1] = ...

id use this

local flashes = 3
local colors = {
[1] = BrickColor.new("Really red"),
[2] = BrickColor.new("New Yeller"),
[3] = BrickColor.new("Lime green"),
}

local tool = script.Parent
local chargepart = script.Parent:FindFirstChild("Charge")

tool.Activated:Connect(function()
flashes -= 1

local color = colors[flashes]
if color then
    chargepart.BrickColor = color
else
    flashes = 3
    chargepart.BrickColor = color
end

end)

couple syntax errors in yours

rancid cobalt
#

Oh jea
There was ONEhollow

whole snow
#

thanks

#

it's not working?

#

i added a print(flashes) after the flashes -= 1

#

to check if it was the color changing part thats messed up

#

but it still wouldnt print flashes

#

i have this in a localscript as a child of the tool (i've mentioned this before but just making sure)

#

this is the tool (mainscript is this one)

whole snow
#

i thought it might be a problem with the chargepart and did this

local flashes = 3
local tool = script.Parent
local chargepart = tool.Charge
local colors = {
    [1] = BrickColor.new("Really red"),
    [2] = BrickColor.new("New Yeller"),
    [3] = BrickColor.new("Lime green"),
}

tool.Activated:Connect(function()
    flashes -= 1
    print(flashes)
    local color = colors[flashes]
    if chargepart == nil then
        print("FAILED TO FIND CHARGEPART")
    elseif flashes == 1 then
        return(nil)
    else
        chargepart.BrickColor = color
    end
end)
languid berryBOT
#

studio** You are now Level 1! **studio

whole snow
#

to check for the chargepart but i didnt get that print

#

it also doesnt print my flashes?