How to fix character nil when cloning with Archivable. [GUIDE]

Are you trying to clone the player’s character, either for a viewport frame, to keep dead players characters or clone them for another reason, but when you try to clone them the clone is returning as nil?

Well here is a simple fix to prevent that from happening and to successfully clone the player’s character.


But first, for those who aren’t so sure what im talking about here is the issue that most of you may have:

lets say i want to clone the player’s character and this was my script:

local player = game.Players.LocalPlayer
local character = player.Character
local clone = character:Clone()

if clone then
     print("Has clone")
else
     print("No clone")
end

When running the script, it prints “No clone”, which means the clone does not exist, the clone is ‘nil’, and this is likely the issue you are having.

To fix the issue you must add this line into your script before you clone the character:

character.Archivable = true

So your code would look like this:

local player = game.Players.LocalPlayer
local character = player.Character

character.Archivable = true

local clone = character:Clone()

if clone then
     print("Has clone")
else
     print("No clone")
end

And this time, the result would be “Has clone”.

Once you have put the line in, optionally you can turn it off again afterwards with:

character.Archivable = false


So what is Archivable and why does it make this work?

Archivable is a property for basically all instances inside your Roblox game.
Its default to true for basically everything inside your game, except for the player’s character, which has it set to false.

Archivable refers to whether the instance and its descendants can be cloned using clone() and if it can be saved or published.
So since for the player’s character, which has it as false, this determines that their character cannot be cloned using clone() which is why it returns as nil and prints out “No clone” in the code i provided earlier.
When toggled to true, it can be cloned.

Archivable is mainly used for plugins, where the developers don’t want something to be saved or published in your game.
For example, if a plugin placed a model inside your game when activated, if archivable was off, when you published your game or saved it, that model would not be saved or published.
Its also used for if you wish to add temporary developer text, or notes which you don’t want to be saved or published.


Thank you for reading,
I hope this helps someone with their game out there.
Just thought i would make a long guide about Archivable and how to fix this issue as its something i’ve seen happen multiple times.

3 Likes