Volt

getscriptfromthread

Gets the script associated with a thread.

Syntax

getscriptfromthread(thread: thread) -> LuaSourceContainer?

Parameters

ParameterTypeDescription
threadthreadThe thread to check

Returns

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

On this page