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

# getscriptbytecode

> คืน decompressed bytecode string สำหรับ Roblox script object getscriptbytecode ถูก register ไปยัง C++ function เดียวกับ dumpstring ดังนั้นพฤติกรรมเหมือนกัน argument ต้องเป็น object bytecode reader ที่ใช้ร่วมกันรับค่า ClassName คือ ModuleScript, LocalScript, CoreScript และ Script สำหรับ Script นั้น RunContext ต้องเป็น Client หาก ClassName หายไป function จะเกิด "Invalid Instance" หาก ClassName ไม่ใช่ script class ที่รองรับ จะเกิด "Script expected" หากค่าเป็น Script ที่มี RunContext อื่น จะเกิด "Expected a Script with RunContext set to Client" หาก embedded bytecode reference ไม่ถูกต้อง หรือ stored bytecode มีความยาว 8 bytes หรือน้อยกว่า function จะคืน nil มิฉะนั้นจะ decompress stored bytecode ด้วย DecompressBytecode และคืน resulting bytes เป็น Luau string Hash mismatch, too-short compressed data หรือ ZSTD decompression errors จะถูกคืนเป็น error text bytes โดย DecompressBytecode แทนการ throw ที่นี่

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

  ## Arguments

  <ParamField path={"script"} type={"userdata"} required>
    Script object ที่จะอ่าน ค่า ClassName ที่รองรับคือ ModuleScript, LocalScript, CoreScript และ Script ที่มี RunContext Client
  </ParamField>

  ## Returns

  <ResponseField name={"bytecode"} type={"string | nil"}>
    Decompressed bytecode bytes เป็น Luau string, DecompressBytecode error text bytes หรือ nil เมื่อไม่มี embedded bytecode ที่ใช้งานได้
  </ResponseField>

  ## ตัวอย่าง

  Read decompressed bytecode from a supported Roblox script Instance.

  ```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 bytecode = getscriptbytecode(targetScript)
      print(bytecode)
  end
  ```
</div>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.