The code below will remove the player accessory which works but It’s not as fast as I want it to be. When the player resets you can see each accessory being removed within a second, you’ll see a flicker. Is there a more efficient way to write this? I want the code to execute all at once.
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
for i, v in pairs(char:GetChildren()) do
if v:IsA("Accessory") then
if v.Handle:FindFirstChild("FaceCenterAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("LocalCollarAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("FaceFrontAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("BodyFrontAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("WaistCenterAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("NeckAttachment") then
v:Destroy()
elseif v.Handle:FindFirstChild("BodyBackAttachment") then
v:Destroy()
end
end
end
end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
for i, v in pairs(char:GetChildren()) do
if v:IsA("Accessory") then
if v:FindFirstChild("Handle") then
local handle = v:FindFirstChild("Handle")
for i, val in pairs(handle:GetDescendants()) do
val:Destroy()
end
end
end
end
end)
end)
I’m assuming you want the handle to not be deleted. If you want the handle to be deleted as well then use the following instead:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
for i, v in pairs(char:GetChildren()) do
if v:IsA("Accessory") then
if v:FindFirstChild("Handle") then
v:FindFirstChild("Handle"):Destroy()
end
end
end
end)
end)
Thanks for the quick reply but, I want all accessories except and hat and hair removed, the script removes everything. Also, I can still see the accessory being removed from the character. My game is an obby so there would be a lot of respawning in-game and the flicker doesn’t look good.
local attachments = {"FaceCenterAttachment", "LocalCollarAttachment", "FaceFrontAttachment", "BodyFrontAttachment", "WaistCenterAttachment", "NeckAttachment", "BodyBackAttachment"}
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
for i, v in pairs(char:GetChildren()) do
if v:IsA("Accessory") then
for i, val in pairs(v:GetDescendants()) do
if table.find(attachments, val.Name) then
val:FindFirstAncestorOfClass("Accessory"):Destroy()
end
end
end
end
end)
end)