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?
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.
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
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)
.