workspace:GetDescendants() doesn't work

So I copied some code from the api reference here, but the code I have just isn’t doing anything.
Here’s my code:

local descendants = game.Workspace:GetDescendants()

for index, descendant in pairs(descendants) do
	if descendant:IsA("SurfaceLight") then
		descendant.Enabled = false
	end
end

There are also no errors in the console

1 Like

Problem number one. I wouldn’t recommend using the API reference. It is incredibly outdated. I’d recommend using Roblox’s new documentation:

Here’s the link to that


Next, I would try messing around with the code for a minute.

for index, descendant in pairs(workspace:GetDescendants()) do
	if descendant:IsA("SurfaceLight") then
		print("Surface light: "..i)
	end
end

Try it with the print and tell me if it works or not

It still is not printing anything

Wait, I messed up. Where the print is, change “i” to “index”

I don’t typically use “index” in for loops. I’ll usually just use “i” or “_” so I messed up lol

I did that lol but still nothing

1 Like

That’s strange. It works just fine for me in my game.


Do you mind sharing more of the script? Or is that all of the code for the script?

Ohh I figured it out, I didn’t realize script in server storage didn’t run

2 Likes

Oh my god :man_facepalming:

We all make silly mistakes like that at some point lol

1 Like

put a print before your forloop to see if it even runs in the first place. then put a print on the first line of the for loop to see which objects are being read as a descendant

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.