Script doesn't remove players accessories

I’m trying to make a script that checks if the players UserId is a developers UserId and if so deletes their accessories and changes their reflectance to 1.

The problem is it changes the reflectance to 1 and does everything else correctly but it doesn’t delete any of the accessories.

I tried looking for solutions but I didn’t know what to really write.

Here is the script (if you need more information or anything else, please ask)

-- **Script is in StarterCharacterScripts

local BodyParts = {
	"Head",
	"Torso",
	"Right Arm",
	"Right Leg",
	"Left Arm",
	"Left Leg"
}

local Character = script.Parent;
local Player = Players:GetPlayerFromCharacter(Character);

for _, id in pairs(UserIds) do
	if Player then
		if Player.UserId == id then
			for _, part in pairs(Character:GetChildren()) do
				if part:IsA("Accessory") then
					part:Destroy();
				end
				for _, bodyPart in pairs(BodyParts) do
					if part.Name == bodyPart then
						if part.Name == "Head" then
							part.Transparency = 1;
							hasFace = part:FindFirstChildWhichIsA("Decal");
							if hasFace then
								hasFace:Destroy();
							end;
						end;
						part.Reflectance = 1;
						part.Color = Color3.new(41, 222, 255);
						part.Material = Enum.Material.SmoothPlastic
					end;
				end;
			end;
		end;
	end;
end;

Any help is appreciated, thank you so much!

You can do all this in a single line with a built in Roblox function, here it is.

script.Parent.Humanoid:RemoveAccessories()
-- *Script is in StarterCharacterScripts

local BodyParts = {

    "Head",

    "Torso",

    "Right Arm",

    "Right Leg",

    "Left Arm",

    "Left Leg"

}

local Character = script.Parent;

local Player = Players:GetPlayerFromCharacter(Character);

for _, id in pairs(UserIds) do

    if Player then

        if Player.UserId == id then

            Character:WaitForChild("Humanoid"):RemoveAccessories()

            for _, part in pairs(Character:GetChildren()) do

                for _, bodyPart in pairs(BodyParts) do

                    if part.Name == bodyPart then

                        if part.Name == "Head" then

                            part.Transparency = 1;

                            hasFace = part:FindFirstChildWhichIsA("Decal");

                            if hasFace then

                                hasFace:Destroy();

                            end;

                        end;

                        part.Reflectance = 1;

                        part.Color = Color3.new(41, 222, 255);

                        part.Material = Enum.Material.SmoothPlastic

                    end;

                end;

            end;

        end;

    end;

end;

Thanks for the response! For some reason it still didn’t remove my accessories

The script was activating before the player’s accessories could load, use this instead.

wait()
script.Parent.Humanoid:RemoveAccessories()
1 Like
local Players = game:GetService("Players")
local Character = script.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:RemoveAccessories()

local UserIds = {} --This table will need values.

for _, UserId in ipairs(UserIds) do
	if Player then
		if Player.UserId == UserId then
			for _, Child in ipairs(Character:GetChildren()) do
				if Child:IsA("BasePart") then
					if Child.Name ~= "HumanoidRootPart" then
						if Child.Name == "Head" then
							local Face = Child:FindFirstChild("face")
							if Face then
								Face:Destroy()
							end
							Child.Reflectance = 1
							Child.Color = Color3.new(0, 1, 1)
							Child.Material = Enum.Material.SmoothPlastic
						end
					end
				end
			end
		end
	end
end

Your previous Color3.new() call was invalid, its arguments can only be between 0 and 1 inclusively, for each color channel (R, G and B). You would need to use the “Color3.fromRGB()” constructor in order to pass values between 0 and 255 inclusively.