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

Cloning into a table?

It's supposed to clone the children of Officer into the players that are cops. Help would be appreciated

local Hunters = {}
local Cops = {}

local Officer = game.Workspace.Characters.Officer:GetChildren()

local Players = game.Players:GetChildren()

for i,v in pairs(Players) do
table.insert(Hunters,v)
end

function chooseRandomPlayer(fromTeam,toTeam)
	local randomPlayer = nil
	repeat
		randomPlayer = fromTeam[math.random(1,#fromTeam)]
	until randomPlayer
	table.insert(toTeam,randomPlayer)
	for i,v in pairs(Players) do
		if v.Name == randomPlayer.Name then
		for z,b in pairs(Players) do
			if (b.className == "Hat") or (b.className == "CharacterMesh") or (b.className == "Shirt") or (b.className == "Pants") or (b.className == "ShirtGraphic") then
				b:Remove()
			end
			if Cops then
				Officer.Parent = Cops
			end
		end
		table.remove(fromTeam,i)
	end
end
end
chooseRandomPlayer(Hunters, Cops)

2 comments

0

Please explain what you want the code to do. At a glance, it's not really possible to determine what you expect is supposed to happen.

1

there edited it to explain better.

1 answer

Try this in place of lines 24-26:

for _, cop in Cops do
	for _, bit in Officer do
		bit:Clone().Parent = cop
	end
end

1 comment

0

I'm not checking to see if it exist, I'm trying to clone the charactermeshes and the hat into the players that are picked as cops.

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