Duplicate models that have functions in StarterGUI?

If we’re out here Optimizing it another potential issue is if you have models underneath other models we can use recursion to make sure that that won’t be an issue.
image

local button = script.Parent.Parent.TextButton
local button2 = script.Parent.Parent.TextButton2
local button3 = script.Parent.Parent.TextButton3
local selectedColour = script.Parent.Colour.TextLabel
local partsToModify = workspace:WaitForChild("PartsFolder")

RecursionFunction = function(Model)
    for i, v in pairs(Model:GetChildren()) do 
        if v:IsA("BasePart") then
            v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
        elseif v:IsA("Model") then
            RecursionFunction(Model)
        end
    end
end

button3.MouseButton1Down:Connect(RecursionFunction(partsToModify))

button2.MouseButton1Down:Connect(function()
	local lost = workspace:WaitForChild("lost")
    local text = lost.SurfaceGui.TextLabel
	text.TextColor3 = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end)

What would :GetDescendants() and recursion differ from each other?

The :GetDescendants() method eliminates the need for recursion. The idea is the same, that you wish to reach all levels deep within the Folder, which :GetDescendants() solves by returning a table of all descendants (children of children of children, etc.) of the object.

1 Like

As ChiefWildin said, :GetDescendants() gets everything in the place you indicate, even if there are 15 folders inside a folder. Return everything. Everything.


Ok, what if I wanted to have two different buttons that set the color to different colors? Like a Primary and Secondary, would I use the same code? Or would it vary.

1 Like

You can still reuse the same code, just pass in different arguments. Something like the following:

local button = script.Parent.Parent.TextButton
local button2 = script.Parent.Parent.TextButton2
local button3 = script.Parent.Parent.TextButton3
local selectedColour = script.Parent.Colour.TextLabel
local partsToModify = workspace:WaitForChild("PartsFolder")

function modifyParts(newColor)
    for i, v in pairs(partsToModify:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Color = newColor
        end
    end
end

button3.MouseButton1Down:Connect(function()
    modifyParts(Color3.fromRGB(table.unpack(selectedColour.Text:split(", "))))
end)

button.MouseButton1Down:Connect(function()
    modifyParts(Color3.new(1,1,1))
end)

button2.MouseButton1Down:Connect(function()
	local lost = workspace:WaitForChild("lost")
    local text = lost.SurfaceGui.TextLabel
	
	text.TextColor3 = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end)

button and button3 now re-use the same code, but pass in different colors.

1 Like

@reteyetet If you still have any questions, do not hesitate to ask us. On my part, I have no problem answering anything.

1 Like

As mentioned before this is a script for a ColourWheel:


So would I change the code to this?

local button = script.Parent.Parent.TextButton
local button2 = script.Parent.Parent.TextButton2
local button3 = script.Parent.Parent.TextButton3
local selectedColour = script.Parent.Colour.TextLabel
local partsToModify = workspace:WaitForChild("PartsFolder")

function modifyParts(newColor)
    for i, v in pairs(partsToModify:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Color = newColor
        end
    end
end

button3.MouseButton1Down:Connect(function()
    modifyParts(Color3.fromRGB(table.unpack(selectedColour.Text:split(", "))))
end)

button.MouseButton1Down:Connect(function()
    modifyParts(Color3.fromRGB(table.unpack(selectedColour.Text:split(", "))))
end)


button2.MouseButton1Down:Connect(function()
	local lost = workspace:WaitForChild("lost")
    local text = lost.SurfaceGui.TextLabel
	
	text.TextColor3 = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end)
1 Like

Exactly, you should change it as you have shown it to us. If you changed it, and it doesn’t work, let us know.
Wait, you want to change the primary and secondary colors?

1 Like

Is it a seperate set of parts you want to change when clicking Apply secondary?

Snip
Yes, I want it two separate sets.

In this case, you’re assigning both buttons to do the same thing. For what you’re doing, you’ll also want to specify which parts are ‘primary’ and which parts are ‘secondary’, and then pass that into the function as well.
Again, for example:

local button = script.Parent.Parent.TextButton
local button2 = script.Parent.Parent.TextButton2
local button3 = script.Parent.Parent.TextButton3
local selectedColour = script.Parent.Colour.TextLabel
local primaryParts = workspace:WaitForChild("PrimaryPartsFolder")
local secondaryParts = workspace:WaitForChild("SecondaryPartsFolder")

function modifyParts(partsToModify, newColor)
    for i, v in pairs(partsToModify:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Color = newColor
        end
    end
end

button3.MouseButton1Down:Connect(function()
    modifyParts(primaryParts, Color3.fromRGB(table.unpack(selectedColour.Text:split(", "))))
end)

button.MouseButton1Down:Connect(function()
    modifyParts(secondaryParts, Color3.fromRGB(table.unpack(selectedColour.Text:split(", "))))
end)


button2.MouseButton1Down:Connect(function()
	local lost = workspace:WaitForChild("lost")
    local text = lost.SurfaceGui.TextLabel
	
	text.TextColor3 = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end)

This assumes that button3 and button are the ‘Apply Primary’ and ‘Apply Secondary’ buttons shown, respectively

To give players more colour design.

Oh ya, in that case you should do it as directed, again, ChiefWildin.

Would secondaryParts and primaryParts be folder/model for the parts?

1 Like

Yes, they would be two separate folders for the primary and secondary parts/models

2 Likes

Off topic:

@reteyetet @ChiefWildin
I have sent you both a friend request, in case you have any further questions you can contact us directly. Or if you need / prefer that we help you directly with the code (TeamCreate)
(I usually respond faster by Roblox chat)

1 Like

Ok this is what I got in Explorer
Folder
Quick question back to my original question: Where would I put the new copies of the model? I believe I have mentioned before, that this GUI is different for each client.

If you want a different copy of the model for each player, put the original model into ReplicatedStorage, and then clone it into the Camera at the beginning of your script. This creates a client-only version of the model that won’t go to the server.

If you’re just making more of the model that any player can edit, then you’ll just clone it within that same folder that you have already.

That might be confusing, does that make sense to you?

2 Likes

If you want each client to look different, I recommend you look at this tutorial, made by Alvin_Blox, so you can create local parts (different for each client). Since if you copy it to the server, it would be the same for all clients.

It’s basically what ChiefWildin explains, but in a video.

1 Like