Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I find the origin of an Instance?

Asked by 8 years ago

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
I'm reasonably sure that is impossible. You would have to keep track of it yourself BlackJPI 2658 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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
Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question