"Attempt to Index nil with 'Name'" on Client Script

Hi, please help me.

I’m trying to make it so when the player loads in, a copy of their character is put inside of a Viewport Frame, so I can put their character inside the frame and animate it for my FPS game.

I tried doing this:

if not game:IsLoaded() then
	game.Loaded:Wait()
end

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

if Player and Character then
	local ViewportCharacter = Character:Clone()
	ViewportCharacter.Name = "Viewport_Character" -- this line causes an error
end

but it throws an error saying " attempt to index nil with ‘Name’ " which means the clone of the character doesn’t exist, yet if I called

if Player and Character then
	print(Character)
end

it prints my username, which works just fine.

I’m really confused, and tried switching things around, and even to give the client an extra 10 seconds of leisure time before running this. I don’t quite understand why it prints the original character just fine, but then immediately throws an error if I try to create a clone and change anything. Even if I try to print the name of that clone, it fails.

Could someone explain to me why that is, and how to fix it?

I preferably don’t want to use HumanoidDescriptions

1 Like

Character’s Archiveable property is false, meaning cannot be cloned. You can enable the character’s archiveable to true and disable it after cloned.
https://developer.roblox.com/en-us/api-reference/function/Instance/Clone

1 Like

Could you tell me the best way I can safely set archivable, clone it, then set it back after being archivable? Could you also explain why the Character is unarchivable by default?

1 Like

To be honest, i don’t usually do anything about character/instance cloning, i just set it to true and then false (someone might get a better approach). And about the character’s archiveable… i don’t know

I had this exact problem months ago and i solved it by the holy google, the project was abandoned as always

1 Like

It appears the clone has absolutely nothing in it. I’m really confused.
image
for context: I printed the descendants of the clone

1 Like

Oh right, i think you’d need to set the clone’s descendants archiveable to true

1 Like

Note: i used server script instead of localscript so the solution might vary

1 Like

You can clone the local player’s character on the client but you need to wait for their appearance to load first.

if not game:IsLoaded() then
	game.Loaded:Wait()
end

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character.Archivable = true
if not Player:HasAppearanceLoaded() then
	Player.CharacterAppearanceLoaded:Wait()
end
task.wait()
local CharacterClone = Character:Clone()
CharacterClone.Parent = workspace
3 Likes

I use custom characters where I have AutoLoadAppearance off. Using StarterCharacter I did not find very practical.

I just clone needed accessories from server storage on join, among other things.

I’ve honestly settled for a fake rig in the replicated storage that gets cloned over and copies stuff from the character. Although I have to manually set body colors and stuff, it’s worth it for my use case.

1 Like