Attempt to index nil with copy

So I’m getting and error with my script: Attempt to index nil with copy

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character 
	
	local copy = char:Copy()

	copy.Name = ' '
	copy.Parent = workspace
	copy.HumanoidRootPart.Position = CFrame.new(workspace:WaitForChild('Game'):FindFirstChild('GreenScreen'):FindFirstChild('tp').CFrame)

	for i,v in pairs(copy:GetChildren()) do
		if v:IsA('Script') or v:IsA('LocalScript') then
			v:Destroy()
		end
	end
end)

Change that line to this:

local char = Player.Character or Player.CharacterAdded:wait()

@ZombieCrunchUK Now i’m getting: Attempt to index nil with name

Try to activate Archivable

local char = plr.Character or plr.CharacterAdded:wait()
char.Archivable = true
local copy = char:Clone()

Archivable by default is off in the characters and this is what prompts to clone.

1 Like

use :Wait() not :wait()

use :Clone() not :Copy()

I did, still nothing. I’m not sure why i thought it was copy.

	local char = plr.Character or plr.CharacterAdded:wait()
	
	local copy = char:Clone()

	copy.Name = ' '
	copy.Parent = workspace
	copy.HumanoidRootPart.Position = CFrame.new(workspace:WaitForChild('Game'):FindFirstChild('GreenScreen'):FindFirstChild('tp').CFrame)

	for i,v in pairs(copy:GetChildren()) do
		if v:IsA('Script') or v:IsA('LocalScript') then
			v:Destroy()
		end
	end
end)

do you want to run the code every time you respawn in the game or only run once?

only run once, when the player jins the game

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	
	local copy = char:Clone()

	copy.Archivable = true
	copy.Name = ' '
	copy.HumanoidRootPart.Position = CFrame.new(workspace:WaitForChild('Game'):FindFirstChild('GreenScreen'):FindFirstChild('tp').CFrame)
	copy.Parent = workspace

	for i, v in ipairs(copy:GetDescendants()) do
		if v:IsA('Script') or v:IsA('LocalScript') then
			v:Destroy()
		end
	end
end)

does this work?

Like how @SOTR654 said, make the archivable property to true like so:


game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	
	local copy = char:Clone()
    copy.Archivable = true

	copy.Name = ' '
    copy.Parent = workspace
	copy.HumanoidRootPart.Position = CFrame.new(workspace:WaitForChild('Game'):FindFirstChild('GreenScreen'):FindFirstChild('tp').CFrame)

	for i, v in ipairs(copy:GetDescendants()) do
		if v:IsA('Script') or v:IsA('LocalScript') then
			v:Destroy()
		end
	end
end)

But the script is cloning the character. If you clone something, you won’t be able to see it until it is parented to something. If there is no parent, then the code would be useless as the character clone would be stuck in memory.

I actually don’t know what the point of this code is, I’m just trying to solve the problem here which is that his code couldn’t access the character for whatever he needs it for.

Yeah ik, but he is cloning the character. That means that whatever change he made to the clone, he won’t do anything to actual character that the user would be currently playing in.
I don’t understand

since the script is dealing with the clone of a character and not the ACTUAL character itself. So you would need to parent the clone to something at least


looked at the api my bad, it does not have the same parent

Edit: you should set the parent after the position is changed, I also updated my code so others don’t get confused

I agree with that, so you can avoid any latency on the code!