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

How to disable all Pointlights in the game?

Asked by
Nidoxs 190
8 years ago

I tried this but it didn't work. How would I go through every model and part to find all the Pointlights and SpotLights and disable them? I know it's possible and I can't just group the Pointlights and use that model because they are all in various models throughout the game and would be VERY VERY time consuming to find them all. If you could help It would be much appreciated.

How would I enhance this?

for i, v in pairs(game.Workspace:GetChildren())do
 if v:FindFirstChild("PointLight") then
    v.PointLight.Enabled = false
end
end

1 answer

Log in to vote
2
Answered by 8 years ago

Hey there!

We can use, I believe what is called, a recursive function, or a function that will call itself. Let's start out with this:

function Search(place)

end

Search(game.Workspace)

Now that we have those basics, we are going to use a

for

statement to help us out.

function Search(place)
    for _,part in pairs(place:GetChildren()) do

    end
end

Search(game.Workspace)

Now we will need an

if

statement to check if it's a point light. I'm going to finish up the code here, as it seems you know how to do an if statement

function Search(place)
    for _,part in pairs(place:GetChildren()) do
        if part:IsA("PointLight") then
            part.Enabled = false
        else -- But what if it isn't a point light? Give up? Naw.
            Search(part)
        end
    end
end

Search(game.Workspace)
0
Thanks so much! Now I can get on with what I've been wanting to do for hours! MUCH APPRECIATED! Nidoxs 190 — 8y
Ad

Answer this question