Hello! I am @Enchanted_Tix, and I was having a question or two. What is descendants and Recursion? How do I use it? I am really confused on what this is. For example, I am making it where if it has a descendant of a ObjectValue named like, “_Water” how will I detect it using “_Water”? Please answer my question(s).
Edit:How do I make it like where the script searches EVERY part of the game and checks if it has a value named, “_Water”?
Here is an article on descendants to help you out. I don’t focus too much on this instance, for I never really have a use for it, but I do know some things about it.
descendants is basically all the children of whatever model you are referring to and the children of models/parts inside of that model you have referred to. Literally a continuous :GetChildren instance in one statement if you were to use the :GetDescendants instance.
for your extra question you can do a loop to search for the part your looking for and use the :GetChildren instance since the descendants one will not be a good use for your extra problem.
[TESTED]
Example:
for _, w in pairs(workspace:GetChildren()) do -- change workspace to the parent of "_Water"
if w.Name == "_Water" then -- finds the child "_Water"
-- code here
end
end
I’ll have a code example of exactly what you need in a few moments
--Function to checkForWater
local function checkForWater(parent)
--Iterate through all children (Descendants) of object
for a, object in pairs(parent:GetChildren()) do
--If object is a model or folder, call this function (recursion)
if (object:IsA("Folder") or object:IsA("Model")) then
checkForWater(object)
else
--If objece.Name is water, run your code here
if (object.Name == "_Water") then
end
end
end
end
well there is no feature for checking descendants in workspace, replicatedstorage, etc. in one line altogether, you would have to do this separately I believe.