Attempt to index nil with 'Parent' | Clone

So i maked a script for clone the player, but is give me error, i try to use WaitForChild but not work, after i try to copy the player and past it in workspace and is work but if i try to direct copy the player skin is give me error
sender = player object


commands.clone = function(sender, arguments)
	if isAdmin(sender) then
		local playerToClone = arguments[1]
		if playerToClone then
			local Plr = findPlayer(playerToClone)
			if Plr then
				local PlrChar = game.Workspace[Plr.Name]:Clone()
				PlrChar.Parent = game.Workspace
			end
		end
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

image

There are lots of functions inside this script that are not clear. Could you include these functions, too?

findPlayer return player in workspace

isAdmin verify in a list if user is admin and return true or false
arguments is arguments with the command for the exemple now the arguments 1 is the player name

use this instead

local PlrChar = Plr.Character:Clone()
1 Like

Could you send me the code for the functions, so I can verify there is nothing wrong with them?

@dispeller Not working :confused: same error

this is the function

local admins = { -- NEED USERID
	604793674, -- Med367367
	-1, -- Player1
	658239819, -- Retopamazing2016
	150767290, -- HorribleThomasG
	1108960519, -- DadSpegatit
	1108960519,--TekiSama
}
--Functions
local function isAdmin(player)-- Need Player Object
	for _, v in pairs(admins) do
		if v == player.UserId then
			return true
		end
	end
	return false
end

local function isAdminWithID(userID)-- Need Player ID
	for _, v in pairs(admins) do
		if v == userID then
			return true
		end
	end
	return false
end

local function findPlayer(name)

	for i, player in pairs(game.Players:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player -- Return the player Object
		end
	end
	return nil
end

Can you include your error in your Original Post?

1 Like

You don’t need the colon in the last line of the table.

yes, but this is change nothing the problem is with clone not the command

Also, why are you returning two things? Try only returning the player

This is happening because, by default, Roblox sets the Archivable property of the character model to false. Archivable determines if something can be cloned and if it can be saved. Because Archivable is set to false Instance:Clone returns nil.

Before cloning, do

Plr.Character.Archivable = true

And yeah don’t do workspace[player.Name] because it can interfere with other instances that coincidentially have the same name as a player. And because that is reinventing the wheel and there is no reason to reinvent the wheel.

13 Likes

Thx is work :slight_smile:
30 characterrrrrrr

1 Like

When I try this in roblox studio it crashes, why?