I have this script that should get the children of a GUI Framehange their background color based on the value BrickColor (Or their name!) However, for some reason it tries to change the properties of the Frame. How can I get it to change the color of the textbuttons inside instead? Thanks for any help
local G = script.Parent for _,v in pairs(G:GetChildren()) do local brickcolor = BrickColor.new(v.BrickColor.Value) -- or v.Name local color = brickcolor.Color v.BackgroundColor3 = Color3.new(color) wait(0.1) script:Destroy() end
Alternatively--
local G = script.Parent for i = 1, #(G:GetChildren()) do local brickcolor = BrickColor.new(G.BrickColor.Value) local color = brickcolor.Color G.BackgroundColor3 = Color3.new(color) wait(0.1) script:Destroy() end
local G = script.Parent for _,v in pairs(G:GetChildren()) do -- v represents one object in the table returned by :GetChildren() local brickcolor = BrickColor.new(v.BrickColor.Value) -- or v.Name local color = brickcolor.Color v.BackgroundColor3 = Color3.new(color) wait(0.1) script:Destroy() -- This destroys the script after the first colouring. end
local G = script.Parent for _,v in pairs(G:GetChildren()) do if v:IsA("TextButton") then -- Checks whether the classname of v is TextButton; that's used to prevent the script from trying to colour a script and breaking by that if v:FindFirstChild("BrickColor") then -- Checks whether there is the BrickColor value local brickcolor = BrickColor.new(v.BrickColor.Value) local color = brickcolor.Color v.BackgroundColor3 = color -- the color variable should be enough already. elseif BrickColor.new(v.Name) then -- Checks whether the name would make a BrickColor local brickcolor = BrickColor.new(v.Name) local color = brickcolor.Color v.BackgroundColor3 = color -- the color variable should be enough already. end wait(0.1) -- You could just remove this to make it seem like it all changes the colour in the same moment. end script:Destroy() -- Now that the :Destroy() is after the loop it will destroy the script afterwards and not during the coloruing.
If you have any other questions, feel free to ask!