Clone SurfaceLight into same parts (should be easy)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to clone the SurfaceLights from these parts into the other parts with the same model name.
  2. What is the issue? Include screenshots / videos if possible!
    I have over 100…that I’d have to manually add surfacelight too and edit the surfacelight property…

Normal model without SurfaceLight:
image
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

No solutions yet.

You seem to have three models with the name “Model” on the same hierarchy level (under one model called “Model”, which is under the “Traffic Light” model). Do they contain different things?

image
image

Mainly focusing on the Model(s) with Traffic Light - set A

Select the Traffic light model that contains the surface lights in the explorer. Then run this code in the command bar.

local mainTrafficLight = game:GetService("Selection"):Get()[1] -- the one that contains the surface lights
local gLight, rLight, yLight
for i, v in ipairs(mainTrafficLight.Model:GetChildren()) do
    local setA = v:FindFirstChild("Traffic Light - set A")
    if setA then
        print("set A found in main traffic light")
        gLight, rLight, yLight = setA.G:FindFirstChildOfClass("SurfaceLight"), setA.R:FindFirstChildOfClass("SurfaceLight"), setA.Y:FindFirstChildOfClass("SurfaceLight")
        if gLight and rLight and yLight then
            break
        end
    end
end

print(gLight, rLight, yLight)

for i, v in ipairs(workspace:GetChildren()) do
    if v.Name == "Traffic Light" and v ~= mainTrafficLight then
        print ("Found a traffic light model")
        for i, model in ipairs(v.Model:GetChildren()) do
            local setA = model:FindFirstChild("Traffic Light - set A")
            if setA then
                print("set A found")
                rLight:Clone().Parent, gLight:Clone().Parent, yLight:Clone().Parent = setA.R, setA.G, setA.Y
            end
        end
    end
end
1 Like

I’ve tried that, nothing happens:

  14:46:36.655  SurfaceLight is not a valid member of Part "Workspace.Traffic Light.Model.Model.Traffic Light - set A.G"  -  Edit
  14:46:36.655  Stack Begin  -  Studio
  14:46:36.656  Script 'local mainTrafficLight = game:GetService("Selection"):Get()[1]
local gLight, rLight, yLight
for i, v in ipairs(mainTrafficLight.Model:GetChildren()) do
    local setA = v:FindFirstChild("Traffic Light - set A")
    if setA then
        gLight, rLight, yLi', Line 6  -  Studio
  14:46:36.656  Stack End  -  Studio

Errors that when I select Traffic Light Model:
image

I edited the code a little. Does it now work?

Your code does execute, but it doesn’t clone it into the other Traffic Light models.

I now added a few prints. What is printed in the output?

It worked, thank you for the help.