Recently, I have been trying to make a clothes/accessory spawner when a player joins a specific team and there character has loaded. It adds the clothes and accessories fine just… the hat remover doesn’t work for some reason. Any and all help will be appreciated, so thank you in advance!
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local folder = script:FindFirstChild(player.Team.Name)
if folder then
local tools = folder:FindFirstChild("Tools")
if tools then
for i,v in pairs(tools:GetChildren()) do
v:Clone().Parent = player.Backpack
end
end
local clothes = folder:FindFirstChild("Clothes")
if clothes then
for i,v in pairs(clothes:GetChildren()) do
local clothing = character:FindFirstChild(v.Name)
local db = true
if clothing then
clothing:Destroy()
end
v:Clone().Parent = character
end
end
local accessories = folder:FindFirstChild("Accessories")
if accessories then
for i,v in pairs(accessories:GetChildren()) do
if v.Name == "Hat" then
for _,eaccessories in pairs(character:GetChildren()) do
print(eaccessories)
if eaccessories:IsA("Accessory") then
print(eaccessories)
eaccessories:Destroy()
end
local g = v:Clone()
g.Parent = character
local C = g:GetChildren()
if g then
for i=1, #C do
if C[i].className == "Part" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
g.Middle.Transparency = 1
end
local Y = Instance.new("Weld")
Y.Part0 = character.Head
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end
end
end
end
end)
end)
--//Hat Remover\\--
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local d = character:GetChildren()
for i = 1,#d do
print(d[i])
if d[i]:IsA("Accessory") then
d[i]:Destroy()
end
end
end)
end)