Hello!
I am currently trying to change multiple parts colors in a model with a script when a button is pressed! I don’t know what to do, I would like help as it is very much appreciated!
Thanks!
Sorry for any grammar mistakes this is my first post.
function colorAllParts(object, brickColor)
if object:IsA("BasePart") then
object.BrickColor = brickColor
end
for _, child in ipairs(object:GetChildren()) do -- Check if that part has any children
colorAllParts(child, brickColor)
end
end
colorAllParts(Model, Color)
Thats exactly what those methods both listed above do. Both are essentially receiving a table of every child of that model object. Checking whether that child is a basePart, and if it is then change the color of the said basePart. Except the one I listed above recursively checks the objects inside of the object ( if there are any ) and changes their color too
function colorAllParts(object, brickColor)
if object:IsA("BasePart") then
object.BrickColor = brickColor
end
for _, child in ipairs(object:GetChildren()) do -- Check if that part has any children
colorAllParts(child, brickColor)
end
end
[THE PATH TO YOUR TEXT BUTTON].MouseButton1Click:Connect(function()
colorAllParts( The model want to change color of, the color you want to change it to )
end)
You should first study how referencing variables and instances work and then events and things like that. Since you barely know code, it’ll be considered as spoonfeeding code as you have no actual attempt that you have tried yourself. You should also learn how GUI and properties work so then instead of being spoonfed code without knowing what it does, you know how to do it yourself and understand it!
Your post also gives very little information, you don’t include what type of Gui you want to be clicked. Is it a surface gui?
The code you just sent to OP also has some bad practices. Localscripts are client sided and therefore do not function in the workspace. You also should reference the gui by either using script.Parent, or PlayerGui. (Move your local script into the TextButton)
If you also want the color changing bricks to be visible to everyone you should fire a remote event so the server can actually see it. Here is more information on them: RemoteEvent.
The OP will understand how to make use of the code given to him once he learns the basic’s himself.
As of now the OP is beyond help until he improves his current capabilities of the basics
If you know the basics of Lua, put two and two together! Use events when necessary, use variables referencing when necessary, instead of asking to be spoonfed code.
I am ending this discussion until tomorrow as I am tired. I will reply to any posts tomorrow if I still don’t understand. @dibblydubblydoo Also, I am not asking to be spoonfed code, I was asking for guidance, not asking someone to write all the code for me.
In earlier posts, you have mentioned that you had no idea what you were doing even after someone had given you a full explanation. You had bad practices and my post did actually guide you to use correct practices. Since this statement;
I implied you were struggling with understanding it, so i have mentioned to relearn the API.