Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I find the origin of an Instance?

Ok let's say I have a script create an instance such as a brick and it puts it in workspace. Am I able to find what script created that brick through the brick? I'm looking all over to find a way of finding the source of an instance but can't seem to find anything on it. Anyone know?

1 comment

1

I'm reasonably sure that is impossible. You would have to keep track of it yourself

2 answers

Although you can not directly track what script made an instance, you can make a function that acts as a proxy to the instance.new function and track what script is using that proxy. This can be done with a ModuleScript:

return function(class, parent)
	-- The script that called this function is set to getfenv(0).script
	return Instance.new(class, parent) -- You should handle errors made from this function so not every instance creating script breaks (if 1 script uses Instance.new incorrectly).
end

You can then have each script that creates instances use this ModuleScript: Instance.new(class, parent) would become require(ModuleScript)(class, parent).

You might be able to use debug.traceback() but it would have to be called from a script that is linked to where the part is created.

Click here for link

Code from the wiki:-

-- Ran from a Script in workspace called "Script"
local function a()
	print(debug.traceback())
end
function b()
	a()
end
local function c()
	b()
end
c()

Output:-

Script 'Workspace.Script', Line 3 - upvalue a
Script 'Workspace.Script', Line 6 - global b
Script 'Workspace.Script', Line 9 - local c
Script 'Workspace.Script', Line 11
Stack End

This discussion is preserved as it was. New answers, comments, and votes are closed.