How to make the players all plain except for their head

How would I make the players body for example just plain gray without any accessories except for their head

If I understand correctly, you want to remove all accessories except for hat accessories. Accessories have an AccessoryType property you can read that, as you may guess, denotes which type of accessory it is (Hat, Hair, Face, Front, etc.)

This script will clear the player’s non-hat accessories and change their body color on spawn
Put it in StarterCharacterScripts

--[[ Variables ]]--
-- Services --
local Players = game:GetService("Players")

-- Character --
local player = Players:GetPlayerFromCharacter(script.Parent)
local character = script.Parent

--[[ Functions ]]--
local function removeAccessories() : ()
	local allowedAccessoryTypes = {
		Enum.AccessoryType.Hat,
		--// you can add more here if needed
	}
	
	for _, v in character:GetChildren() do
		if not v:IsA("Accessory") then
			continue
		end
		
		local isAllowed = table.find(allowedAccessoryTypes, v.AccessoryType) ~= nil
		if not isAllowed then
			v:Destroy()
		end
	end
end

local function setBodyColor(color : Color3) : ()
	local bodyColors = character:FindFirstChildWhichIsA("BodyColors")
	
	bodyColors.HeadColor3 = color
	bodyColors.LeftArmColor3 = color
	bodyColors.LeftLegColor3 = color
	bodyColors.RightArmColor3 = color
	bodyColors.RightLegColor3 = color
	bodyColors.TorsoColor3 = color
end

local function onSpawn() : ()
	if not player:HasAppearanceLoaded() then
		player.CharacterAppearanceLoaded:Wait()
	end
	
	removeAccessories()
	
	--// Change color if necessary
	local bodyColor = Color3.fromRGB(163, 162, 165)
	setBodyColor(bodyColor)
end
onSpawn()

1 Like

So much bloatware bruuuhhh too slow and unoptimized.
I also assume he uses client so yeah

local Players = game:GetService("Players")
local plr = Players.LocalPlayer::Player

local function CleanUpChar(char:Model):()
	if not plr:HasAppearanceLoaded() then plr.CharacterAppearanceLoaded:Wait() end
	for i,v in char:GetChildren() do
		if v:IsA("Accoutrement") then v:Destroy() end
	end
end
plr.CharacterAdded:Connect(CleanUpChar)
local char:Model? = plr.Character
if char then
	CleanUpChar(char)
end

Also dictionary > table.find

OP wanted a script to remove all but one kind of accessory and I provided a code sample that is easy to read and understand.
I would’ve defended my “bloated” and “unoptimized” programming style here but I’ve noticed every argument you instigate on this forum is in bad faith and hardly constructive, so I really don’t care enough to

4 Likes

That’s not really about personal preference - code either runs efficiently or it doesn’t.
Here’s a more optimized approach you can compare with your solution:

local Players = game:GetService("Players")
local plr = Players.LocalPlayer::Player
local evil:{[Enum.AccessoryType]:true} = {
	[Enum.AccessoryType.Face]=true;
	[Enum.AccessoryType.Neck]=true;
	[Enum.AccessoryType.Hat]=true;
	[Enum.AccessoryType.Hair]=true;
	[Enum.AccessoryType.Eyebrow]=true;
	[Enum.AccessoryType.Eyelash]=true;
}

local function CleanUpChar(char:Model):()
	if not plr:HasAppearanceLoaded() then plr.CharacterAppearanceLoaded:Wait() end
	for i,v in char:GetChildren() do
		if not v:IsA("Accessory") or evil[(v::Accessory).AccessoryType] then continue end
		v:Destroy()
	end
end
plr.CharacterAdded:Connect(CleanUpChar)
local char:Model? = plr.Character
if char then
	CleanUpChar(char)
end

Sure, using a dictionary look up over table.find() would’ve saved a few microseconds, but micro optimizations aren’t something I care for. They both get the job done just fine

Unless you have something to actually add here, send it in a DM, it just seems you’re derailing the topic for the sake of optimizations, when OP just wants something that works, and both scripts do indeed work

4 Likes

To be honest, I would prefer to use @nkmisoup’s script over yours as it seems a lot easier to read.

Plus, crucially, they answered the OP’s question… you pointed out bloatware (which even outside of this context seems irrelevant) in someone else’s script instead of actually helping in a help category.

2 Likes

I get it, readability is nice.

But my reply wasn’t just “helping OP” - it was about showing which patterns are actually efficient. OP might not notice now, but understanding how the code executes prevents bigger headaches later.

“Easy to read” ~= “efficient.” If your code needs comments everywhere, that’s a red flag. Your goal is to make code run optimally - no one will care about source clarity, even if yo’re working with others.

1 Like