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

BrickColor Based On BrickColorValue Not WOrking?

local value = script.Parent.Parent.ColorValue
local mchild = script.Parent:GetChildren("ColorMeSkin")

if value.Value == "" then
for i,v in pairs(mchild) do
v.BrickColor = BrickColor.new(value.Value)       
        print(v)
    end
end

simply if i change the brickcolorvalue it should change the bricks named "colormeskin" to the choosen color in the brickcolorvalue but it does not work nor do i get errors.

2 comments

0

Could we have the error?

0

@UltChowsk 'it does not work nor do i get errors' - I've answered it anyway, it was a logic error and a few other errors that didn't show because the part of the code they were in never ran.

1 answer

✓ Accepted answer

What you've done will only run once, not every time the value is changed. Also, you're checking if the value of the ColorValue is equal to an empty string, which will never be true as a BrickColor value is never equal to a string, that would be the reason it's not doing anything, even on the only time it runs. To fix it, have a .Changed event listener and run the for loop each time that is fired, and also don't compare the value of ColorValue to a string. Another problem that would occur is that it would error when it gets to changing the brick color, as you've set it to practically BrickColor.new(BrickColor.new("White")) which would error because it would be expecting a string, not a brick color. Finally, printing v will give you an error simply because v will be an object and you can't print objects, only strings, integers and other similar values. Here's the code you should use:

local value = script.Parent.Parent.ColorValue
local mchild = script.Parent:GetChildren("ColorMeSkin")

value.Changed:connect(function() -- Runs each time value is changed
    for i,v in pairs(mchild) do
        v.BrickColor = value.Value -- Not BrickColor.new(value.Value)
        print(v.Name) -- .Name added to prevent it erroring
    end
end)

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