The Script Works Perfect The Only Problem Is that it spawns the player hats and the hat that I inserted in script. How will i be able to add a hat remover to this script and make it not remove the hat in the script?

function onChildAdded(child)
	local result = Scan(child)
	if result then
		wait(1)
		local list = script:GetChildren()
		for i = 1,#list do
			local copy = list[i]:clone()
			if (copy:IsA("Script")) then
				copy.Parent = child
				copy.Disabled = false
			elseif (copy:IsA("Part")) then
				if (copy.Name == "Hair") or (copy.Name == "Hat") then
					local head = child:findFirstChild("Head")
					if (head ~= nil) and (head:IsA("BasePart")) then
						local hatscan = child:GetChildren()
						for i = 1,#hatscan do
							local obj = hatscan[i]
							if (obj:IsA("Hat")) then
								obj:remove()
							end
						end
						copy.Parent = child
						local weld = Instance.new("Weld",copy)
						weld.Part0 = copy
						weld.Part1 = head
						weld.C1 = CFrame.new(copy.CFrameOffset.Value.x,copy.CFrameOffset.Value.y,copy.CFrameOffset.Value.z)
					end
				end
			elseif (copy:IsA("Shirt")) then
				local oldshirt = child:findFirstChild("Shirt")
				if (oldshirt ~= nil) then
					oldshirt:remove()
				end
				copy.Parent = child
			elseif (copy:IsA("Pants")) then
				local oldpants = child:findFirstChild("Pants")
				if (oldpants ~= nil) then
					oldpants:remove()
				end
				copy.Parent = child
			elseif (copy:IsA("Decal")) then
				if (copy.Name == "face") then
					local head = child:findFirstChild("Head")
					if (head ~= nil) and (head:IsA("BasePart")) then
						head.face:remove()
						copy.Parent = head
					end
				elseif (copy.Name == "roblox") then
					local torso = child:findFirstChild("Torso")
					if (torso ~= nil) and (torso:IsA("BasePart")) then
						torso.roblox:remove()
						copy.Parent = torso
					end
				end
			elseif (copy:IsA("BodyColors")) then
				local colors = child:findFirstChild("Body Colors")
				if (colors ~= nil) then
					colors:remove()
				end
				copy.Parent = child
			end
		end
	end
end

function Scan(it)
local IsACharacter = false
local list = game.Players:GetChildren()
for i = 1,#list do
if (it == list[i].Character) then
IsACharacter = true
end
end
return IsACharacter
end

workspace.ChildAdded:connect(onChildAdded)

2 comments

0

Clearly you're an experienced scripter, so I don't need to code anything for you, but just add a bit to the function which uses the "for" statement to search the Player's children, removes everything with the classname "Hat," then once that is done THEN adds the hat you wanted.

0

Thanks It worked :D