I have a model that I want to make more copies of. But the model gets its functions and features from StarterGUI, and the scripts in StarterGUI state for example:
local part7 = workspace:WaitForChild("p3")
and so on. Does anyone have a solution or alternative to this?
To put it simply I have a model that has functions in StarterGUI, but those functions are linked to that one model from this
local lost = workspace:WaitForChild("lost")
local part2 = workspace:WaitForChild("lost")
local part3 = workspace:WaitForChild("click")
local part4 = workspace:WaitForChild("Partee")
local part5 = workspace:WaitForChild("p1")
local part6 = workspace:WaitForChild("p2")
If I want to make more copies of that model, with the same functions what do I do?
This is not a very efficient way of doing this. You will need to share more information to help us answer in the best way possible: Sharing more code and screenshots could help.
I recommend grouping all of these and then changing the script to reference them like this
local model = game.Workspace.Model
local part7 = model["p3"]
From here you could duplicate both the model, and the script and just change the names.
If Iâm reading this right, you have a model in workspace (called âp3â?) that you want to clone, but there are functions in a script in StarterGui (and by extension, each PlayerGui) that use that model that would need to be duplicated as well for the cloned model. Am I correct with all of that?
The simple way to do this is to rename the variableâs to different names. But I want to know if there is another way to do this easier? I have to do this about 55 times so I am in desperate need.
Put all the parts that you need to modify into a Model or a Folder in workspace. Then, iterate through the Model or Folder and do what you need to do for each one. In your case, itâd look something like 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")
button3.MouseButton1Down:Connect(function()
for i, v in pairs(partsToModify:GetChildren()) do
v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end
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)
Where âpartsToModifyâ is the Folder that contains all the parts that youâre talking about duplicating.
Yes, but youâll handle each one differently. For example:
for i, v in pairs(partsToModify:GetChildren()) do
if v:IsA("BasePart") then
v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
elseif v:IsA("Model") then
for index, child in pairs(v:GetChildren()) do
if child:IsA("BasePart") then
child.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end
end
end
end
In this case I think you should use :GetDescendants()
(Sorry if Iâm wrong.)
If I remember correctly :GetChildren() only returns the first things it finds.
Instead :GetDescendants() returns EVERYTHING he finds wherever you indicate.
Youâre right, you could also use :GetDescendants(), it just depends on how deep into the children you wish to go. Using :GetDescendants(), the solution would be
for i, v in pairs(partsToModify:GetDescendants()) do
if v:IsA("BasePart") then
v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end
end
And it will change any and every BasePart-derived object it finds within partsToModify. Thanks for the suggestion @nanitook
This is how my code is looking so far. Is there any potential errors?
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")
button3.MouseButton1Down:Connect(function()
for i, v in pairs(partsToModify:GetChildren()) do
if v:IsA("BasePart") then
v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
elseif v:IsA("Model") then
for index, child in pairs(v:GetChildren()) do
if child:IsA("BasePart") then
child.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end
end
end
end
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)
I donât see any errors with the code. Your indentationâs slightly off, but that wonât affect functionality. Just know that this wonât account for models within models that you place in partsToModify. To reach all levels deep within the Folder, use the :GetDescendants() that I posted, which was suggested by nanitook.
Yes, now reading it better I am realizing the same. script.Parent.Colour.TextLabel doesnât make much sense if you want to change the color.
Sorry about that.
Yes this is for a Colour wheel. Here is the updated code:
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")
button3.MouseButton1Down:Connect(function()
for i, v in pairs(partsToModify:GetDescendants()) do
if v:IsA("BasePart") then
v.Color = Color3.fromRGB(table.unpack(selectedColour.Text:split(", ")))
end
end
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)