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
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)
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.
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.