function ReturnWorkspace() for i,v in pairs(workspace:GetChildren()) do return {Index = i , Value = v} end end print(ReturnWorkspace().Index) -- Only prints 1 and prints Camera if I do v -- Since I have 6 things in workspace it should return 6 for index but its returning only 1
Why does this not return everything in workspace
it only returns camera and prints it for some reason?
Anyone know a fix to this?
So I can return every single thing in workspace
Whenever you use return, the entire function stops. that's how return functions, so after 1 iteration your entire function stops and returns the current value.
What you should do instead is something like this, which will return all of them.
function ReturnWorkspace() local tab = {} for i,v in pairs(workspace:GetChildren()) do tab[i] = v end return tab end print(ReturnWorkspace()[1])
This will return all of the workspace's children with their respective index (numbers) and values (objects).