Recursive search or iterate loop?

What’s preventing me from using workspace:FindFirstChlid(<string>, true) instead of workspace:GetDescendants()? Perhaps performance or is a loop guaranteed to find the instance?
I am using it for cases like this.

local Proms = {}
for _,v:ProximityPrompt? in workspace:GetDescendants() do
	if v:IsA("ProximityPrompt") then
		if v.Enabled == true then
			v.Enabled = false
			table.insert(Proms, tostring(v))
		end
	end
end
for _,v in Proms do
	workspace:FindFirstChild(v, true).Enabled = true
end
Proms = {}

Correct me if I’m wrong, however using workspace:FindFirstChild(name: string, recursive: boolean) has a ‘significant’ difference in compute speed compared to something like workspace[name: string].

You should mostly be using workspace[name: string].

Update:
In your example you could just use:

local proximityPrompts: any = {} :: any

for index: number, proximityPrompt: ProximityPrompt in pairs(workspace:GetDescendants()) do
	if (proximityPrompt:IsA("ProximityPrompt")) then
		if (proximityPrompt.Enabled) then
			proximityPrompt.Enabled = false :: boolean
			proximityPrompts[#proximityPrompts + 1] = proximityPrompt :: ProximityPrompt 
		end
	end
end

for index: number, proximityPrompt: ProximityPrompt in pairs(proximityPrompts :: any) do
	proximityPrompt.Enabled = true :: boolean
end

proximityPrompts = {} :: any

Pardon me if this doesn’t answer your question.

2 Likes

I like the typechecking. Appericate it.

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