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

Can you do two GetDescendants?

Asked by 5 years ago

So the code for the Spotlight but I added the Part new color and it does not work now? Any issues you see here or you simply can't do x2?

script.Parent.MouseButton1Down:Connect(function()
    if game.Workspace.Games.Colors.ColorsLightSystem.CeilingWhite.Value.Value == true then 
        game.Workspace.Games.Colors.ColorsLightSystem.CeilingWhite.Value.Value = false

            for _, v in pairs(workspace.Games.Colors.ColorsLightSystem.CeilingWhite:GetDescendants()) do
            if v:IsA("SpotLight") then
                v.Brightness = 10


            for _, v in pairs(workspace.Games.Colors.ColorsLightSystem.CeilingWhite:GetDescendants()) do
            if v:IsA("Part") then
                v.BrickColor.new ("Mid gray")
            end
        end

    else 
          game.Workspace.Games.Colors.ColorsLightSystem.CeilingWhite.Value.Value = true

        for _, v in pairs(workspace.Games.Colors.ColorsLightSystem.CeilingWhite:GetDescendants()) do
            if v:IsA("SpotLight") then
                v.Brightness = 0


            for _, v in pairs(workspace.Games.Colors.ColorsLightSystem.CeilingWhite:GetDescendants()) do
            if v:IsA("Part") then
                v.BrickColor.new ("Institutional white") 
            end
        end
    end
end

while wait() do
 if game.Workspace.Games.Colors.ColorsLightSystem.CeilingWhite.Value.Value == false then 
        script.Parent.ImageColor3 = Color3.fromRGB(130, 243, 0)
    else
        script.Parent.ImageColor3 = Color3.fromRGB(163, 162, 165)
    end
end

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

Your code is really messed up. You made some syntax errors where you tried to set the BrickColor, you put a loop inside the same loop, you don't use variables for the ceiling and you use a while loop to check if the value has changed!

Everything wrong!!!!!

Here is what it should look like:

local ceiling = workspace.Games.Colors.ColorsLightSystem.CeilingWhite --declare it as a variable

script.Parent.MouseButton1Down:Connect(function()
    if ceiling.Value.Value == true then 
        ceiling.Value.Value = false
        for _, v in pairs(ceiling:GetDescendants()) do
            if v:IsA("SpotLight") then
                v.Brightness = 10
            elseif v:IsA("BasePart") then --check if it's a part
                v.BrickColor = BrickColor.new("Mid gray") --set the color like this
            end
        end
    else 
        ceiling.Value.Value = true
        for _, v in pairs(ceiling:GetDescendants()) do
            if v:IsA("SpotLight") then
                v.Brightness = 0
            elseif v:IsA("BasePart") then
                v.BrickColor = BrickColor.new("Institutional white") 
            end
        end
    end
end

ceiling.Value.Changed:Connect(function(val) --use the Changed event to check if the value has changed
    if val then
        script.Parent.ImageColor3 = Color3.fromRGB(163, 162, 165)
    else
        script.Parent.ImageColor3 = Color3.fromRGB(130, 243, 0)
    end
end)

0
Error: (25,1) Expected ')' (to close '(' at line 3), got 'ceiling' AcentrixTheYouTuber -8 — 5y
0
That shouldn't error... There is something you ruined on line 25.. Maybe you delete ceiling in another script.. idk.. greatneil80 2647 — 5y
0
u forgot a parenthesis at the end for the MouseButton1Down event User#23365 30 — 5y
Ad

Answer this question