Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

can you clone more than 1 accessory?

function aaa(part)
	local human  = part.Parent:FindFirstChild("Humanoid")
	if human then
		local dendi = game.Workspace.Dondo:FindFirstChildOfClass("Accessory")
		if dendi then
		local copy = dendi:Clone()
		copy.Parent = game.Players.LocalPlayer.Character
		end
	end 
end
script.Parent.Touched:connect(aaa)

this script should copy the "Accessory" class that found on "Dondo" npc. The problem is there are more then 1 accessory and it only clone 1 accessory only. How to clone all Accessory class to our character?.

1 answer

✓ Accepted answer

You would need to get all of the children of the npc and then check if each child is a accessory. You then need to use the function AddAccessory to add this to the player. Lastly note this needs to be done on the server so you need to find if this is a player first.

A quick example (server script)

local accessory = {} -- store our list of accessories 
for _, itm in pairs(game.Workspace.Dondo) do
	if itm:IsA('Accessory') then -- check if item is a accessory 
		accessory[#accessory+1] = itm
	end
end

script.Parent.Touched:Connect(function(hit)
	if not game.Players:GetPlayerFromCharacter(hit.Parent) then return end -- check if its a player

	local hum = hit.Parent:FindFirstChild('Humanoid')
	if hum then
		for _, itm in pairs(accessory) do
			hum:AddAccessory(itm:Clone()) -- add each accessory to the player
		end
	end
end)

Something like this should be ok but it does not check for existing accessories so you may need to add this in. I hope this helps, please comment if you do not understand how / why this code works.

This discussion is preserved as it was. New answers, comments, and votes are closed.