GetDecendants also gets the parents?

im trying to get the decendants of a model and its also returning with a whole bunch of random parts that arent children of the part

Heres what it gives me:

Heres what it should give me:
image

show us the script… we are not magicians and we need context to figure out what’s wrong

sorry i forgot

local function Dirupt(Detector)
	local Search = Detector.Parent
	print(Detector.Parent)
	local Lights = {}
	
	for _, V in Search:GetDecsendants() do -- HERE
		if V:IsA("BasePart") and V.Material == "Neon" then --and V:FindFirstChildOfClass("PointLight") or V:FindFirstChildOfClass("SpotLight") or V:FindFirstChildOfClass("SurfaceLight")
			table.insert(Lights, V)
		end
	end
--Rest is irrelevant

Its funny i just made a post about this script and now its broken again

BTW, Detectors parent is ALWAYS the model i need to go through

Hi! Can you show us where the script is located in the explorer?

its just a tool but ok
image

Oh, so the line

print(Detector.Parent)

gives “EM-Pulsarr” in the output?

no, it gives “HallwayLight” (It needs to return hallwaylight so that is right)

Sometimes there might be parts im looking for inside of other parts so get children wont work

Okay thanks for the info :slight_smile: . Is the model always there? Like there as soon as the script runs?

For an explanation, detector is the result of the Pulsarr finding a “Detector” part in its range, so “Detector” has nothing to do with the pulsarr

yea it exists
chat limittttttttttttt

I have a feeling this isn’t the code that gave you the output in your original post. Maybe this script didn’t run (it was another older one) or some other part fo your script ran.

Edit: For example, none of the code outputs the list that you showed in your original post.

image

image

hey i got it fixed, but now theres another issue that has come back

(this was happening in my other post)

Okay I’m sorry I didn’t mention this in the beginning, but in order for us scripters to help you very well, you might need to show us larger portions of your code. I get that you’re trying to prevent others from “stealing” but we really don’t.

So like, you might have to explain more what you’re trying to do, what not working, and post the entire lines, not just a small sample of lines…

Edit: For example, what’s the rest?
image

i got it fixed sorry, just this one error left:

Try spelling it as GetDescendants instead.

now theres a giant lag spike, heres the whole function:

local function Dirupt(Detector)
	local Search = Detector.Parent
	print(Detector.Parent)
	local Lights = {}
	
	for _, V in Search:GetDescendants() do -- HERE
		if V:IsA("BasePart") and V.Material == "Neon" then --and V:FindFirstChildOfClass("PointLight") or V:FindFirstChildOfClass("SpotLight") or V:FindFirstChildOfClass("SurfaceLight")
			table.insert(Lights, V)
		end
	end
	
	local Times = math.random(1, 3)
	local Doin = false
	
	print(Lights)


	Doin = true

	task.spawn(function()
		while Doin == true do
			for _, V in Lights do
				if V:FindFirstChildOfClass("SpotLight") then
					V.SpotLight.Enabled = false
				end
				if V:FindFirstChildOfClass("PointLight") then
					V.PointLight.Enabled = false
				end
				if V:FindFirstChildOfClass("SurfaceLightLight") then
					V.SpotLight.Enabled = false
				end
				V.Color = Color3.fromRGB(0, 0, 0)
				task.wait(tonumber("0.0"..math.random(1, 9)))
				V.SpotLight.Enabled = true
				V.PointLight.Enabled = true
				V.Color = Color3.fromRGB(237, 234, 234)
				task.wait(tonumber("0.0"..math.random(1, 9)))
			end
		end
	end)

	task.wait(Times)
	Doin = false
	for _, V in Lights do
		V.SpotLight.Enabled = true
		V.PointLight.Enabled = true
		V.Color = Color3.fromRGB(237, 234, 234)
	end

end

The lag spike is from your while loop. I recommend using “events” (I don’t mean Roblox Events) to handle it.

Let me know if this works?

local function Dirupt(Detector)
	local Search = Detector.Parent
	print(Detector.Parent)
	local Lights = {}

	for _, V in Search:GetDescendants() do -- HERE
		if V:IsA("BasePart") and V.Material == "Neon" then --and V:FindFirstChildOfClass("PointLight") or V:FindFirstChildOfClass("SpotLight") or V:FindFirstChildOfClass("SurfaceLight")
			table.insert(Lights, V)
		end
	end

	local Times = math.random(1, 3)
	local Doin = true

	print(Lights)

	local function YOUR_FUNCTION_NAME_HERE()
		while Doin == true do
			for _, V in Lights do
				if V:FindFirstChildOfClass("SpotLight") then
					V.SpotLight.Enabled = false
				end
				if V:FindFirstChildOfClass("PointLight") then
					V.PointLight.Enabled = false
				end
				if V:FindFirstChildOfClass("SurfaceLightLight") then
					V.SpotLight.Enabled = false
				end
				V.Color = Color3.fromRGB(0, 0, 0)
				task.wait(tonumber("0.0"..math.random(1, 9)))
				V.SpotLight.Enabled = true
				V.PointLight.Enabled = true
				V.Color = Color3.fromRGB(237, 234, 234)
				task.wait(tonumber("0.0"..math.random(1, 9)))
			end
		end
	end

	-- Start it. Same thing as the task.spawn thing in your original script.
	local thread = coroutine.create(YOUR_FUNCTION_NAME_HERE)
	coroutine.resume(thread)

	task.wait(Times)
	Doin = false
	task.wait()
	coroutine.close(thread)
	
	for _, V in Lights do
		V.SpotLight.Enabled = true
		V.PointLight.Enabled = true
		V.Color = Color3.fromRGB(237, 234, 234)
	end
end