Find every child of a part

How can I find all the proximity prompts under a model (DirtWall_Model)


local model = game.Workspace.DirtWall_Model


if model and model:IsA("Model") then
	local proximityPrompts = {}

	for _, part in ipairs(model:GetDescendants()) do
		if part:IsA("ProximityPrompt") then
			table.insert(proximityPrompts, part)
		end
	end

	print("Found " .. #proximityPrompts .. " ProximityPrompts")

end

image

1 Like

You should generally be using pairs() instead of ipairs(), if that’s what you’re after

1 Like

Fixed: Needed a wait(5) statement at start of script to ensure proximity prompts loaded in

that works too. but if the reason is the lag in loading in of the proximity prompts, i’d personally use WaitForChild(), just in case it took longer than 5 seconds for other players.

1 Like

I’d highly advise against this because there is no guarantee it’ll take 5 seconds.

You don’t need either. Generalised iteration exists now.

1 Like

Interesting, since when? I definitely remember ipairs being dodgy

Honestly better approach would be using .ChildAdded connection. You never actually know if proximityprompt loads in 5 seconds because it is arbitrary.

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