Problems With Returning Array of Instances?

The value that it’s supposed to return is an array of instances, but it’s printing out nil. I’m not sure why it’s printing out nil because it reaches the else block and is supposed to return the curList. When I print out the curList inside of the function, it prints out table: id. When I print out the curList outside of the function, it prints nil.

local ServerScriptService = game:GetService("ServerScriptService")
local Map = require(ServerScriptService.Libraries.Main.Map)

local function checkForLinked(check, curList)
	local objValue = check:FindFirstChild("objvalue", true)
	local curList = curList or {}

	if objValue then
		table.insert(curList, objValue.Value)
		checkForLinked(objValue.Value, curList)
	else
		print("Curlist:" , curList) --this is printing out the table
		return curList
	end
end
wait(1)
local list = checkForLinked(workspace.check1)

print("List: ", list)
1 Like

You will want to return checkForLinked(objValue.Value, curList) since you are just calling it but not returning its result.

2 Likes