Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Working with several objects inside a model/group?

Asked by 4 years ago

So I've made this script and it works how I planned (only if used with one part) but I've decided to add more lights. I don't want to have this script into every part and have them named differently. I tried to do it myself and this is what I came up with but doesn't work. Can you guys make it so that this script goes to a model (StageILights) then selects all the parts inside of it and enables the PointLights?

StageILights (model) LigtherSII (Parts)

h = workspace.LightsOn

function touch(hit)
    if hit then
    h:FindFirstChild("Humanoid")
workspace.StageILights:GetChildren("LighterSII").PointLight = true
    end
end

script.Parent.Touched:Connect(touch)

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Use for i loops to figure out which part has a pointlight and which doesnt

function touch(hit)
    if hit then
        local H = hit.Parent:FindFirstChild('Humanoid')
        if H then
            local StageILights = workspace:FindFirstChild('StageILights')
            if StageILights then
                for _,v in pairs(StageILights:GetChildren()) do
                    if v:FindFirstChild('PointLight') then
                        v.PointLight.Enabled = true
                    end
                end
            end
        end
    end
end

script.Parent.Touched:Connect(touch)

1
Thank you! ItsJZaid 45 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I was a little confused by what you are asking, but If I'm understanding correctly this should work

h = workspace.LightsOn

function touch(hit)
    if hit then
        h:FindFirstChild("Humanoid")
        local lights = workspace.StageILights:GetChildren("LighterSII")
        for i, v in pairs(lights) do
            v.PointLight = true
        end
    end
end

script.Parent.Touched:Connect(touch)

0
Thank you! ItsJZaid 45 — 4y

Answer this question