> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# getscriptthread

> Tra ve Lua thread lien ket voi script object khi Real co the tim thay. Argument phai la object. Function doc field ClassName cua gia tri va nem "not a valid Instance" neu field do khong phai string. Cac gia tri ClassName duoc chap nhan la Script, LocalScript va ModuleScript; bat ky gia tri nao khac nem "Script expected". Dau tien no kiem tra ScriptThreadCache cua Real bang script reference. Khi cache hit, no tra ve Luau thread da cache nhu mot thread. Khi cache miss, cac gia tri Script phai co RunContext Client, neu khong function nem "Expected a Script with RunContext set to Client". Sau do no di qua the live Luau thread list, theo first weak thread reference cua moi thread node toi LiveLuaRef, bo qua missing thread data hoac expired Script stored references, va so sanh moi script reference voi script duoc yeu cau. Neu tim thay match, no tra ve Luau thread do nhu thread. Neu khong tim thay match, no tra ve nil.

<div className="real-function-page">
  ```lua theme={null}
  getscriptthread(script: userdata): thread | nil
  ```

  ## Đối số

  <ParamField path={"script"} type={"userdata"} required>
    Script object can tim. Cac gia tri ClassName duoc chap nhan la Script, LocalScript va ModuleScript.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"thread"} type={"thread | nil"}>
    Lua thread lien ket, hoac nil khi khong tim thay matching live thread.
  </ResponseField>

  ## Ví dụ

  Read the Luau thread associated with a supported script Instance when one is available.

  ```lua theme={null}
  local targetScript

  for _, descendant in ipairs(game:GetDescendants()) do
      if descendant:IsA("LuaSourceContainer") then
          targetScript = descendant
          break
      end
  end

  if targetScript then
      local thread = getscriptthread(targetScript)
      print(thread)
  end
  ```
</div>
