Attempted to index number with clone

There’s an error at line 53 that says “Attempted to index number with clone” But I dont understand what the problem is. It’s supposed to pick clothing items from different folders that are there.

local default_death_sounds = {"rbxassetid://146594640", "rbxassetid://146594648", "rbxassetid://146457047"}
local body_part_names = {"Head", "LeftArm", "LeftLeg", "RightArm", "RightLeg", "Torso"}
local hairs = script.Folder['Hairs']:GetChildren()
local faces = script.Folder['Faces']:GetChildren()
local shirts = script.Folder['Shirts']:GetChildren()
local pants = script.Folder['Pants']:GetChildren()
local hair = math.random(1, #hairs)
local facelol = math.random(1, #faces)
local shirt = math.random(1, #shirts)
local pant = math.random(1, #pants)

--functions-----

local TypeList = { --All available effect types for this kill effect
	NoDeletion = function(model, common_functions, cleanup_time, ppos) 

		common_functions.DefaultDamageReceiverHandle(model, cleanup_time, ppos)
	end,
	Damaged = function(model, common_functions, cleanup_time, ppos) 
		
	end,
	Character = function(model, hum, common_functions, cleanup_time, ppos) --Run the full effect on a character
		common_functions.PlaySoundInPart(model:FindFirstChild("Torso"), default_death_sounds)
		common_functions.RemoveClothing(model)
		common_functions.RemoveHats(model)
		
		local b_col = model:FindFirstChild("Body Colors")
		if b_col ~= nil then
			for _, nm in pairs(body_part_names) do
				b_col[nm .. "Color"] = BrickColor.new("Pastel brown")
			end
		end
		
		pant:Clone()
		shirt:Clone()
		hair:Clone()
		hair.Name = "Hair"
		pant.Name = "Pants"
		shirt.Name = "Shirt"
		hair.Parent = model
		shirt.Parent = model
		pant.Parent = model
		
		local head = model:FindFirstChild("Head")
		if head ~= nil then
			local face = head:FindFirstChild("face")
			if face ~= nil then
				face.Texture = facelol
			end
		end
		
		local physService = game:GetService("PhysicsService")
		for i,v in ipairs(model:GetChildren()) do
			if v:IsA("BasePart") then
				physService:SetPartCollisionGroup(v, "ragdolls")
			end
		end
		
		return common_functions.DefaultRagdollHandle(model, hum, cleanup_time, ppos) --has to return object for death cam to attach to
	end,
	Universal = function(model, common_functions, cleanup_time, ppos) --Run the effect on a non-character model with full permissions for altering
		common_functions.DefaultDamageReceiverHandle(model, cleanup_time, ppos)
	end,
}

return TypeList

You are cloning a randomly generated number between 1 and the item count, you can clone only objects, not numbers

So then how would I have it pick the clothing item then clone it

The solution could be to import objects into lists with for loops and then take a random object with a random number from 1 to the length of the list

1 Like

I don’t understand, when you say lists do you mean like tables?

1 Like

You are currently generating a random number from 1 to the amount in the table, but you need take that index from the table.

local default_death_sounds = {"rbxassetid://146594640", "rbxassetid://146594648", "rbxassetid://146457047"}
local body_part_names = {"Head", "LeftArm", "LeftLeg", "RightArm", "RightLeg", "Torso"}
local hairs = script.Folder['Hairs']:GetChildren()
local faces = script.Folder['Faces']:GetChildren()
local shirts = script.Folder['Shirts']:GetChildren()
local pants = script.Folder['Pants']:GetChildren()
local hair = pants[math.random(1, #hairs)]
local facelol = faces[math.random(1, #faces)]
local shirt = shirts[math.random(1, #shirts)]
local pant = pants[math.random(1, #pants)]

I put in what you put but it’s still giving the same error.

try with this:

local hairs = {}
local faces = {}
local shirts = {}
local pants = {}

for i, v in pairs(script.Folder['Hairs']) do
    hairs[i] = v
end
for i, v in pairs(script.Folder['Faces']) do
    faces[i] = v
end
for i, v in pairs(script.Folder['Shirts']) do
    shirts[i] = v
end
for i, v in pairs(script.Folder['Pants']) do
    pants[i] = v
end

local hair = pants[math.random(1, #hairs)]
local facelol = faces[math.random(1, #faces)]
local shirt = shirts[math.random(1, #shirts)]
local pant = pants[math.random(1, #pants)]

That wouldn’t really change anything as if it’s a table it just copies it.
(Also I guess it’s likely an Instance so it would error as pairs in Luau only works for tables)

this will looks like

local table = {
    [1] = object1
    [2] = object2
    --- more items..
}

so when the code

local hair = pants[math.random(1, #hairs)]

search for the random number the table will return the object

EDIT: it should do this automatically, so idk

just tried using it, it didn’t work (same error) its in a module script if that changes anything

Are you sure the error is the same? theoretically it is no longer trying to clone a number

yep. it’s the same for sure. same error same line

Then i don’t know, the @XdJackyboiiXd21 's script should work fine, have you replaced all the lines?