Help with disabling clothing remover

I am fairly new to this but I am trying to disable my function if a player is on a certain team but just for that team. Say a person was on the grey I am removing all clothes except for that team. This is my script so far:

Any help would be appreciated

1 Like

Use Something Like This:

local Players = game:GetService("Players")

-- For Cleaning One Player:
local function CleanPlayer(Player, NotColor)
	
	if Player ~= NotColor then return end
		
	local Character = Player.Character
		
	for _, CharacterInstance in ipairs(Character:GetChildren()) do
		
		if CharacterInstance:IsA("Shirt") or CharacterInstance:IsA("Pants") then
			CharacterInstance:Destroy()
		end
		
	end
end

-- If You Want To Clear All Players In One Go:
local function CleanPlayers(NotColor)
	
	for _, Player in ipairs(Players:GetPlayers()) do
		CleanPlayer(NotColor)
	end
		
end

-- Something Like You Made:

local NotColor = "Medium Stone Grey"

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Chatacter)
		
		CleanPlayer(NotColor)
		
	end)
end)
1 Like

You can use the ClearCharacterAppearance function to do this much easily

game.Players.PlayerAdded:Connect(function(Plr)
     if Plr.TeamColor ~= "Medium stone grey" then
           Plr:ClearCharacterAppearance()
     end
end)

If that doesn’t work do this:

game.Players.PlayerAdded:Connect(function(Plr)
     if Plr.TeamColor ~= "Medium stone grey" then
           Plr.Character:ClearCharacterAppearance()
     end
end)

Edit* Put ~= instead of == *
My bad sry

1 Like

That’s the Opposite. Use “~=” not “==”

So would this be for clearing character appearance for that color team, correct?

For all of them in one go would I assign the variable before the function or like how u put it?

How I put it should probably be fine

If you want to to it for that color team switch the ~= with the ==

Like destroying their clothing?

I think so…
It should remove all the clothing/accessories… so I think so

But for my script how would I make it so only one team keeps their clothing because I already have the script to remove a players clothing when joined

game.Players.PlayerAdded:Connect(function(Plr)
     if Plr.TeamColor ~= "Medium stone grey" then
          CleanPlayer(Plr.Character)
     end
end)

This will call your CleanPlayer function on every team except Medium stone grey

Where would I position this in my current script based on the picture I posted?

1 Like

Lines 26 - 30 should be replaced with this

First of all, that’s impossible. Unless…

local function foo(bar)
print(bar)
end
--use the function
foo("hello world")
--disable the function
foo = function()end
--try to use the function again
foo("hello world")

This is probably what you don’t want to do, but again, this is my understanding of “disabling a function”.

I would rather use an if statement if I were you.

1 Like

I think it would be easier just to do a ~= condition so the function won’t even begin for that team

1 Like

Seems not to be working maybe something similar?

When I try and use this script it either seems not to work at all or deletes the clothes but for every team.

I did an oopsie

Corected Code:

local Players = game:GetService("Players")

-- For Cleaning One Player:
local function CleanPlayer(Player, NotColor)
	
	if Player.TeamColor ~= NotColor then return end
		
	local Character = Player.Character
	if Character == nil then return end
	
	for _, CharacterInstance in ipairs(Character:GetChildren()) do
		
		if CharacterInstance:IsA("Shirt") or CharacterInstance:IsA("Pants") then
			CharacterInstance:Destroy()
		end
		
	end
end

-- If You Want To Clear All Players In One Go:
local function CleanPlayers(NotColor)
	
	for _, Player in ipairs(Players:GetPlayers()) do
		CleanPlayer(Player, NotColor)
	end
		
end

-- Something Like You Made:

local NotColor = "Medium Stone Grey"

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Chatacter)
		
		CleanPlayer(Player, NotColor)
		
	end)
end)

It was 2 am and I made the code without Studio or Autocorrect. I never filled in the parameters.