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

# setnamecallmethod

Rewrites the method name dispatched by the active `__namecall` metamethod.

```luau theme={null}
setnamecallmethod(method: string): ()
```

Takes a string and replaces the method name on the active namecall, so dispatch routes to the new method instead of the one the caller originally asked for. Only meaningful inside a `__namecall` metamethod.

Most commonly used inside a `hookmetamethod(game, "__namecall", ...)` hook to swap the called method for any other one you want.

## Parameters

| Parameter | Type     | Description                                       |
| --------- | -------- | ------------------------------------------------- |
| `method`  | `string` | Method name to dispatch in place of the original. |

## Returns

<code title="the function does not return a value.">void</code>

## Example

Find an RPG game with loot mechanics, where a client ModuleScript loops through items on the ground and calls `:PickUp()` on each one. Filter the call so only rare items go through; common ones get redirected to a method that destroys them.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  setnamecallmethod("__index")
  =======
  -- setnamecallmethod(method: string): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local mt = getrawmetatable(game)
  setreadonly(mt, false)

  local oldNamecall
  oldNamecall = hookmetamethod(game, "__namecall", function(self, ...)
      if getnamecallmethod() == "PickUp" and rawget(self, "Rarity") == "Common" then
          setnamecallmethod("Destroy") -- Destroy takes no args

          return oldNamecall(self)
      end

      return oldNamecall(self, ...)
  end)
  ```
</CodeGroup>

<Tip>
  Useful for redirecting call flows in custom `__namecall` hooks.
</Tip>
