Accessory remover does not work

I don’t know why but still doesn’t workkk

I am going for 20 minutes… i illm come

1 Like

Does it error? And how much of it doesn’t work?

i didn’t test wait…I will do it

No nothing this will never be solved

Anything else??No? What do I do?

Oh sorry, I’m not on my PC right now. I’ll debug it in the morning

The issue here is that you never started a for object, you copy and pasted this chopping off the correct piece of code, I am making a new one rn but studio is bugging

Edit: also you cannot connect to accessory, it will just be null

Fixed it, try using this @alekos204x

for _, obj in pairs(char:GetChildren()) do

if obj:IsA("Accessory") then

	obj:Destroy()


	end)
end
1 Like

I wrote that code way before this topic existed. It works just fine in my game by deleting accessories as they load in. The reason why it won’t be great in his case is it will also delete the accessory he wants to put on the character unless he defines the function and manually disconnects it.

Okay @alekos204x as I said before I can’t really boot up the PC at the moment to insert the script into a baseplate and modify the script for testing, because I have an event I need to attend. If the problem isn’t resolved by tomorrow, I’ll open up Roblox Studio.

I suggest using the version of the script where at least some of it works, then perform prints in every part of the script possible. Prints’ll tell you when parts of the code aren’t running, and can also be concatenated to give you info about the problem! I’m hoping either yourself or another person will have resolved the issue before I’m ready, but I’ll return if that isn’t the case.

I suspect that you haven’t read the entire thread because this is so similar to my reply, just without the hair check(which was a problem I addressed), and without a check for hat objects—

His problem is likely something so obvious that we’re overlooking but I’m pretty sure the for loop itself isn’t the problem

it literally solves the original issue that he had in the post, I cannot believe how incompetent you are when it comes to understanding code and lua.

1 Like

You’re supposed to read the entire thread before posting a solution to make sure you’re not just repeating the same things others have tried. Your solution is no different than mine here

Explain exactly why my solution didn’t work but yours(which is the same as mine) will?

Look, this thread is not a place for excessive argument—there was no need for any of this.

That is incorrect: a childadded event will fire whenever the instance you connect it to has a child added to it, and will return the instance. If an accessory is added to the character, this function will give you the accessory and allow you to do whatever you want to it. It’s worked perfectly fine in my game since I wrote it 6 months ago.

You may be wondering why it isn’t a for loop—well because accessories may take time to load so the for loop may not catch them all instantly. I childadded event will always catch every object added. Anyways none of this matters because the current solutions have failed so we need a new idea

Tenny you’ve been yapping nonsense for the past 30+ posts on this topic. Just let other people try lol

1 Like

There are multiple problems with OP’s script. I’ve fixed two: A typo of “and” instead of “or”, and a check for a non-existent class. Please go ahead and find the remaining problem.

1 Like

2 problems that could have been fixed in 1 post lol. I’ll just fix it cuz you seem incapable.

1 Like

Hey @alekos204x! I recall you mentionned :RemoveAccessories() in a previous post, which seems to be the right solution for your situation. I’ve applied it in your code below. You can find more about it in the Roblox Documentation. Feel free to let me know if you have any questions!

local Players = game:GetService("Players")
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.
		local connection = player.CharacterAppearanceLoaded:Connect(function(character)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			humanoid:RemoveAccessories()
		end)

		player.AncestryChanged:Wait()
		connection:Disconnect()

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

for _, player in Players:GetPlayers() do
	task.spawn(assignPlayer, player)
end

Players.PlayerAdded:Connect(assignPlayer)

Hey @Youf_Dev, that sounds a little rude… I don’t find any need to say it like that… @700000002 just tell “you go ahead, help”.

Specially when you were incapable to do it in the right way either… There is a problem with your approach:

You are connecting a function to an event CharacterAppearanceLoaded “hoping” it didn’t fired yet when calling the assignPlayer() function. But if that event already fired, your script will get stuck forever on that line… And its pretty sure that under many scenarios that event already happen (cause the Appearance already loaded), so it has chances to fail, and there is no way to call that a proper approach:

local function assignPlayer(player)
	-- You expect this event someday happens, if not, script will wait forever...
	local connection = player.CharacterAppearanceLoaded:Connect(function(character)
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		humanoid:RemoveAccessories()
	end)
end

Then, it gets worst, you are waiting for an AncestryChanged to happen in order to clean the connection, which will cause the rest of the code below will never run…

	player.AncestryChanged:Wait()
	connection:Disconnect()
	warn("THE CODE BELOW WILL NEVER RUN")

(Btw I tested your script Im not just saying my thoughts, literally I saw it failing and getting stuck and only in like 5 tests I did, it failed quickly)


Would be better if you dont use a Connection to wait for the event to fire, just check if the Appearance Has loaded, if yes remove the accessories, if not, now you can wait for the event to happen:

	-- Remove all accessories and hair.
	if not player:HasAppearanceLoaded() then
		player.CharacterAppearanceLoaded:Wait()
	end
	local Hum = player.Character:FindFirstChildOfClass("Humanoid")
	Hum:RemoveAccessories()


So, the whole script would be like this @alekos204x :

local Players = game:GetService("Players")
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 -- IF THERE IS NO TEAM DONT SET THE NAME AS NIL NEEDS A STRING
	
	-- 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)
	--warn(player:IsInGroup(groupId), player:GetRankInGroup(groupId)) -- Just to print if Im in group and rank
	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.
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end
		local Hum = player.Character:FindFirstChildOfClass("Humanoid")
		Hum:RemoveAccessories()

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

for _, player in Players:GetPlayers() do
	task.spawn(assignPlayer, player)
end

Players.PlayerAdded:Connect(assignPlayer)
2 Likes