Nil? (IN the command bar.)

my command:

local function GetInstanceByDebugID(DebugId:string) local function Proccesing()  for i,v:Instance in pairs(game:GetDescendants()) do if v:GetDebugId() == DebugId then return v end end  if not Proccesing() and DebugId == game:GetDebugId()  then return game elseif Proccesing() ~= nil  then return Proccesing() end end end local d = GetInstanceByDebugID("0_2085749") print(d)

for some reason it prints nil.
0_2085749 is the game’s debug id.
i used print(game:GetDebugId()) and it said “0_2085749”

Can you format your code?

Paste it into a script and it’ll be formatted for you.

Formatted for anyone who may have an idea yet.

But please @HenryThe_Legendary , do format your ‘commands’ nicely before bringing it here, we don’t want that extra work. :frowning:

local function GetInstanceByDebugID(DebugId:string)
	local function Proccesing()
		for i,v:Instance in pairs(game:GetDescendants()) do
			if v:GetDebugId() == DebugId then
				return v
			end
		end
		if not Proccesing() and DebugId == game:GetDebugId() then
			return game
		elseif Proccesing() ~= nil then
			return Proccesing()
		end
	end
end

local d = GetInstanceByDebugID("0_2085749") print(d)

You did execute the main function, but you did not call Proccessing().

Here’s the formatted code (You can run code from scripts too, not just single-lines):

local function GetInstanceByDebugID(DebugId:string)
	local function Proccesing()
		for i,v:Instance in pairs(game:GetDescendants()) do
			if v:GetDebugId() == DebugId then
				return v
			end
		end
		if not Proccesing() and DebugId == game:GetDebugId()  then
			return game
		elseif Proccesing() ~= nil then
			return Proccesing()
		end
	end
	Proccesing() -- Runs the proccessing function.
end

local d = GetInstanceByDebugID("0_2085749")
print(d)
1 Like

No. they will be not.

what? what do you mean?!
You did not do return Processing() so no necessary to do it

You’re getting descendants of game, not the game…
The descendants is children, childrens children and so on. Not the game…

You’ve gotta do

local Source = game:GetDescendants()
table.insert(Source, game)

-- Run the logic on Source, not game:GetDescendants()

Ah yes, I forgot to add.

return Proccesing() -- Runs the proccesing function and returns its value.

read the full script!