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