Accessory remover does not work

Hello there!

I made a script that removes player’s accessories but it doesn’t work.

This is my script:

            if accessory:IsA("Accessory") or accessory:IsA("Hat") then
                accessory:Destroy()
            end
        end

The problem could be outside of this section you sent us. Could you post more of the script?

local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


-- Assuming the specific group ID and rank ID are known. Replace '123456' with your group ID and '10' with the rank ID.
local groupId = 33119741
local rankId = 1

-- Assuming the team, item, and hat names are known. Replace 'TeamName', 'ItemName', and 'HatName' with actual names.
local teamName = "Presidential Guard"
local itemName = "Musket"
local hatName = "Accessory"

-- Check if the team exists, if not, create it.
local team = Teams:FindFirstChild(teamName)
if not team then
	team = Instance.new("Team", Teams)
	team.Name = nil
	-- You can customize the team color by changing the Color property.
	team.TeamColor = BrickColor.new("Cyan")
end

-- Function to assign player to a team, give item, wear hat, and remove other accessories.
local function assignPlayer(player)
	if player:IsInGroup(groupId) and player:GetRankInGroup(groupId) == rankId then
		player.Team = team

		-- Clone the item from ReplicatedStorage and give it to the player.
		local item = ReplicatedStorage:FindFirstChild(itemName)
		if item then
			item:Clone().Parent = player.Backpack
		end

		-- Remove all accessories and hair.
		for _, accessory in ipairs(player.Character:GetChildren()) do
			if accessory:IsA("Accessory") or accessory:IsA("Hat") and accessory:IsA("Hair") then
				accessory:Destroy()
			end
		end

		-- Wear the specific hat from ReplicatedStorage.
		local hat = ReplicatedStorage:FindFirstChild(hatName)
		if hat then
			hat:Clone().Parent = player.Character
		end
	end
end

-- Connect the function to the PlayerAdded and CharacterAdded events.
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		assignPlayer(player)
	end)
end)
local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


-- Assuming the specific group ID and rank ID are known. Replace '123456' with your group ID and '10' with the rank ID.
local groupId = 33119741
local rankId = 1

-- Assuming the team, item, and hat names are known. Replace 'TeamName', 'ItemName', and 'HatName' with actual names.
local teamName = "Presidential Guard"
local itemName = "Musket"
local hatName = "Accessory"

-- Check if the team exists, if not, create it.
local team = Teams:FindFirstChild(teamName)
if not team then
	team = Instance.new("Team", Teams)
	team.Name = nil
	-- You can customize the team color by changing the Color property.
	team.TeamColor = BrickColor.new("Cyan")
end

-- Function to assign player to a team, give item, wear hat, and remove other accessories.
local function assignPlayer(player)
	if player:IsInGroup(groupId) and player:GetRankInGroup(groupId) == rankId then
		player.Team = team

		-- Clone the item from ReplicatedStorage and give it to the player.
		local item = ReplicatedStorage:FindFirstChild(itemName)
		if item then
			item:Clone().Parent = player.Backpack
		end

		-- Remove all accessories and hair.
		for _, accessory in ipairs(player.Character:GetChildren()) do
			if accessory:IsA("Accessory") or accessory:IsA("Hat") or accessory:IsA("Hair") then
				accessory:Destroy()
			end
		end

		-- Wear the specific hat from ReplicatedStorage.
		local hat = ReplicatedStorage:FindFirstChild(hatName)
		if hat then
			hat:Clone().Parent = player.Character
		end
	end
end

-- Connect the function to the PlayerAdded and CharacterAdded events.
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		assignPlayer(player)
	end)
end)

The loop was checking if the accessory was of two classes at once(which is impossible), since you accidentally typed and instead of or

Jusr blocked the whole script…

Okay then instead of pasting the script I retyped, just replace that and with or, and tell me if that fixes it.

Wait did you change something?

1 Like

Yeah do this

1 Like

Still nothing.I don’t know why. Anything else?

Okay there is no such thing as “Hair” as a class, remove the check for hair, because hair is part of the accesory class I’m sure

change

to

if accessory:IsA("Accessory") or accessory:IsA("Hat") then
1 Like

I did it still doesn’t work the thing is that I solved it a 2 days or even 1 ago but I don’t remember how.

But I m sure it had to do with:

Humanoid:RemoveAccessories(

You have a line like

local Players = game:GetService(“Players”)

right?

Yes but I didn’t copy it there by mistake.

okay well here’s the way I do it in my script:

		character.ChildAdded:Connect(function(accessory)
			if accessory:IsA("Accessory") or accessory:IsA("Hat") then
				accessory:Destroy()
			end
		end)

It some how makes the rest of the script have issues

Well actually this will delete the new hat never mind one sec

local function assignPlayer(player)
	local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
	if not humanoid then print("no humanoid "..player.UserID) return end
	if player:IsInGroup(groupId) and player:GetRankInGroup(groupId) == rankId then
		player.Team = team

		-- Clone the item from ReplicatedStorage and give it to the player.
		local item = ReplicatedStorage:FindFirstChild(itemName)
		if item then
			item:Clone().Parent = player.Backpack
		end

		-- Remove all accessories and hair.
		humanoid:RemoveAccessories()

		-- Wear the specific hat from ReplicatedStorage.
		local hat = ReplicatedStorage:FindFirstChild(hatName)
		if hat then
			hat:Clone().Parent = player.Character
		end
	end
end
2 Likes