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

# cache.replace

Swaps a cached Instance with another so every existing reference to it resolves to the replacement.

```luau theme={null}
cache.replace(old: Instance, new: Instance): ()
```

After the call, any script still holding `old` is really working with `new` - reading `old.Name` returns `new.Name`, and `print(old)` shows `new`. The `old` Instance is no longer reachable through the cache.

Most commonly used to hide a watched Instance from anti-cheat scanners: swap the real object for a harmless decoy so game scripts that re-resolve it through the cache get the decoy, while your code keeps the real one with `cloneref`.

## Parameters

| Parameter | Type                                                                           | Description                                 |
| --------- | ------------------------------------------------------------------------------ | ------------------------------------------- |
| `old`     | [`Instance`](https://create.roblox.com/docs/reference/engine/classes/Instance) | The cached Instance to repoint.             |
| `new`     | [`Instance`](https://create.roblox.com/docs/reference/engine/classes/Instance) | The Instance its references now resolve to. |

## Returns

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

## Example

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  cache.replace(game:GetService("Players"), game:GetService("Players"))
  =======
  -- cache.replace(old: Instance, new: Instance): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local watched = game:GetService("ReplicatedStorage").Remotes.Combat
  local real = cloneref(watched) -- private handle to the genuine RemoteEvent

  -- the game re-resolves this through the cache and lands on the decoy instead
  cache.replace(watched, Instance.new("RemoteEvent"))

  real:FireServer("attack") -- still reaches the real remote
  ```
</CodeGroup>

<Tip>
  Always check parameters and return values when working with this library function.
</Tip>
