Loops not working

Hello! I’ve been learning loops and trying to test my skills. However, this loop does not work! Can anyone help me? The grills are models if that helps.

local Grills = workspace.Grills:GetChildren()

for i, v in pairs(Grills) do
	if v:IsA("ProximityPrompt") then
		v.Enabled = true
		print("Enabled")
		
	end
	
end
2 Likes

Can you show me the entire hierarchy of the grill models? Like, the children and their children

1 Like

Can you provide the entire model of “Grills”?

1 Like

Grill

Use :GetDescendants() instead of :GetChildren()

4 Likes

Alright, I will test it out right now! Ill see if it works

Something like this could also work.

local grills = workspace.Grills

local function getObjects(obj)
	for _, Object in pairs(obj:GetChildren()) do
		if Object:IsA("ProximityPrompt") then
			--something
		elseif Object:IsA("Model") then
			getObjects(Object)
		end
	end
end

getObjects(grills)
1 Like

And if it works, please don’t forget to mark it as solution to close the thread!

2 Likes

It Works! Thank you so much! You saved me so much time or else I would’ve do it manually lol

2 Likes

A bit of a stretch, don’t you think? Not trying to be rude or anything, but it really seems like a little much for such a small change needed.

1 Like

Better to know 1 solution, whilst you can research others afterwards.

2 Likes

Your loop was perfect, but the :GetChildren() method returns a table of ONLY direct descendants. The :GetDescendants() method on the other hand, like you’ve probably guessed, returns a table of all descendants. If you had the ProximityPrompt directly parented under the grills model, your script would’ve ran perfectly, so overall, good try.

1 Like

Thank you! Now I know, did not know that GetChildren() only works if the proximity prompt was under the model.

I also highly recommend you learn how to use CollectionService. It’s great to learn while in the early stages of learning Luau

It’s very easy to use, helps a lot with organizing your code. And it could be used here so you don’t have to go through multiple folders if they’re parented different.

And there are plenty of plugins, I recommend this one most, to help you create tags and tag stuff.

You’re a life saver! I completely forgot to explain why it should be used instead (and the difference between the two). Thank you!

1 Like

Funny thing! I use collection service pretty often!

Well, good for you then! XD

I didn’t learn how to use it until like six months ago, or that it even existed. I’ve been developing on Roblox since December of 2016

1 Like

I didn’t learn how to use it until like six months ago, or that it even existed. I’ve been developing on Roblox since December of 2016

This is so relatable lmao

1 Like

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