I’m making custom functions to find objects, and I’ve ran into a problem.
I have a GetSiblings() function, but its not working:
function module:GetSiblings(Object : any?) -- Gets all siblings of a declared object
local SiblingTable = {}
if not Object then
warn("Attempted to GetSiblings() on a nil object")
end
for index, variable in pairs(Object.Parent:GetChildren()) do
table.insert(SiblingTable, variable)
return SiblingTable
end
end
Script handling function:
local SiblingFunctions = require(script.Parent.SiblingFunctions)
for i,v in pairs(SiblingFunctions:GetSiblings(workspace.Baseplate)) do
print(i) -- only returns one
print(v) -- only returns "Camera"
end
What I mean is you need to return the table, “SiblingTable” AFTER the loop
function module:GetSiblings(Object : any?) -- Gets all siblings of a declared object
local SiblingTable = {}
if not Object then
warn("Attempted to GetSiblings() on a nil object")
end
for index, variable in pairs(Object.Parent:GetChildren()) do
table.insert(SiblingTable, variable)
end
return SiblingTable
end