Can someone help with this function not being able to but in string

So I have this function but I don’t know how I can put it into a string so if someone could help me I would be greatful

Here is the function

function FancyPrint(Name, Object, Recursions)
	local Padding = string.rep(" ", Recursions * 4)
	if Recursions == 20 then
		print(Padding.."Reached recursion limit")
		return
	end
	local Otype = string.format("[%s]", type(Object))
	Otype = string.rep(" ", 10 - #Otype) .. Otype
	print(('%s> %s "%s" - %s'):format(Padding, Otype, Name, tostring((typeof(Object) == "Instance" and Object:GetFullName() or typeof(Object) == "string" and '"'..Object..'"' or Object))))
	if type(Object) == "table" then
		for I,V in pairs(Object) do
			FancyPrint(I, V, Recursions + 1)
		end
	end
end

Example of what I want to be able to do

local String = FancyPrint()

The problem ios that it wont let me do taht and I do not know why

IF SOMEONE CAN HELP I WOULD BE GREATFUL

Also I want it to return things like

"A", "B", "C", 1, 2, 3

SO IF I CAN GET IT TO RETURN THAT I WOULD BE HAPPY

Instead of

print(Padding.."Reached recursion limit")

Do this

print(Padding .. “Reached Recursion Limite”)

Hmmm… wondering if there is something else which I can do which does something

That does not help or do anything at all

Here is a copy of a deep print that handles infinitely deep recursion and cycles without imposing a hard limit that I wrote a couple years ago:

local l = '   |'

local lines, cache, count
local function deepPrint(data, prefix)
	if cache[data] then
		lines[#lines + 1] = prefix .. '[' .. cache[data] .. ']'
		return
	end

	count = count + 1
	local name = 'table_' .. count
	cache[data] = name

	for key, value in next, data do
		local valuet = type(value)
		local keyt = type(key)
		if keyt == 'table' then
			lines[#lines + 1] = prefix .. '[{'
			deepPrint(key, prefix .. l)
			if valuet == 'table' then
				lines[#lines + 1] = prefix .. '}] = {'
				deepPrint(value, prefix .. l)
				lines[#lines + 1] = prefix .. '};'
			end
		elseif valuet == 'table' then
			lines[#lines + 1] = prefix .. tostring(key) .. ' = {'
			deepPrint(value, prefix .. l)
			lines[#lines + 1] = prefix .. '};'
		elseif type(value) == 'string' then
			lines[#lines + 1] = prefix .. tostring(key) .. ' = "' .. tostring(value) .. '";'
		else
			lines[#lines + 1] = prefix .. tostring(key) .. ' = ' .. tostring(value) .. ';'
		end
	end
end

local function firstCall(data)
	lines, cache, count = {}, {}, 0
	deepPrint(data, '')
	local str = table.concat(lines, '\n')
	lines, cache, count = nil, nil, nil
	return str
end

return firstCall

This works as a module and the returned function will stringify any value.
I should add that you should pass this to print() if you want to see the string

Does it return it like:]

returned = "spawn", "place", "graden", 10, 2

???

It will output the key-value pairs with semicolons and newlines:

1 = "spawn";
2 = "place";
3 = "graden";
4 = 10;
5 = 2;

If you would like a different format, you can easily modify the script. What is the use case?

I have this table that fires things

eg

network:send("Spawn"

And I have a local script which catches it

in a for loop and I want the for loop to return the thing fired

eg

network:send("Spawn")

THAT WOULD BE GREAT

Also why is this not working then?

local l = '	'

local lines, cache, count
local function deepPrint(data, prefix)
	if cache[data] then
		lines[#lines + 1] = prefix .. '[' .. cache[data] .. ']'
		return
	end

	count = count + 1
	local name = 'table_' .. count
	cache[data] = name

	for key, value in next, data do
		local valuet = type(value)
		local keyt = type(key)
		if keyt == 'table' then
			lines[#lines + 1] = prefix .. '[{'
			deepPrint(key, prefix .. l)
			if valuet == 'table' then
				lines[#lines + 1] = prefix .. '}] = {'
				deepPrint(value, prefix .. l)
				lines[#lines + 1] = prefix .. '},'
			end
		elseif valuet == 'table' then
			lines[#lines + 1] = prefix .. tostring(key) .. ' = {'
			deepPrint(value, prefix .. l)
			lines[#lines + 1] = prefix .. '},'
		elseif type(value) == 'string' then
			lines[#lines + 1] = '"' .. tostring(value) .. '",'
		else
			if type(value) == "Instance" then
				lines[#lines + 1] = GetFullName(value) .. ','
			end
		end
	end
end

local function firstCall(data)
	lines, cache, count = {}, {}, 0
	deepPrint(data, '')
	local str = table.concat(lines, '\n')
	lines, cache, count = nil, nil, nil
	return str
end

print(firstCall({workspace}))