getscriptfromthread
Gets the script associated with a thread.
Syntax
getscriptfromthread(thread: thread) -> LuaSourceContainer?Parameters
| Parameter | Type | Description |
|---|---|---|
thread | thread | The thread to check |
Returns
| Type | Description |
|---|---|
LuaSourceContainer? | The script, or nil if none associated |
Description
getscriptfromthread returns the script (LocalScript, ModuleScript, or Script) that is running in the specified thread.
Example
local script = getscriptfromthread(coroutine.running())
if script then
print("Current script:", script:GetFullName())
end
-- Check what script a connection is from
local connection
connection = game:GetService("RunService").Heartbeat:Connect(function()
local thread = coroutine.running()
local scriptSource = getscriptfromthread(thread)
if scriptSource then
print("Heartbeat from:", scriptSource.Name)
end
connection:Disconnect()
end)Related Functions
getcallingscript- Get calling scriptgetrunningscripts- Get all running scripts