Disabling my clothing remover for one team

I have a script that removes clothing for all players on player added but im trying to avoid that if you join the medium stone grey team. I want the player to keep their regular Roblox clothing if they are on that team. This is something I have tried to do but doesnt seem to work:
Screen Shot 2022-07-30 at 09.16.32

Any help would be nice! :slight_smile:

1 Like

You’ll have to specify a condition for the player’s team.

if player.Team == game.Teams.ThisTeam then
    -- What you want the script to do when they are on 'Medium Stone Grey'.
end

When you call the CleanPlayer() function for the loop, you need to add another parameter for your script to work.

CleanPlayer(Player, NotColor)

and “ThisTeam” would be my team correct?

Yes, I would recommend to direct the path to the team’s parent in the explorer because it is easier to edit.

Screen Shot 2022-07-30 at 09.30.43

I did something like this but it doesn’t seem to be working should I try a different way to remove the clothing or characters appearance or am I making an error?

local Players = game:GetService("Players")
local IgnoreTeams = {game.Teams.Red}

local function CleanPlayer(player)
	for _,team in pairs(IgnoreTeams) do
		if player.Team == team then return end
	end
	
	local character = player.Character or player.CharacterAdded:Wait()
	
	if character then
		for _,characterInstance in ipairs(character:GetChildren()) do
			if characterInstance:IsA("Shirt") or characterInstance:IsA("Pants") then
				characterInstance:Destroy()
			end
		end
	end
end

local function CleanPlayers()
	for _,player in ipairs(Players:GetPlayers()) do
		CleanPlayer(player)
	end
end

Doesn’t seem to remove the clothing if your not on the red team.

That is because you need to connect the event to the function.
I recommend that you read the luau documentation pages on how to connect a function to an event.
Having a good basic understanding of how connections work will get you very far in scripting.

Thank you. I appreciate it very much!

So all I need to do for it to work is connect the function to the event fired? How would that go because I am not very good at scripting tbh and I can’t find anything on the topic you told me to explore.


@umamidayo like this?

That’d work, you could also do if table.find(IgnoreTeams, Player.Team) then return end too.

which line are you talking about or where or what?

image

The part of your script that checks the player’s team.

The thing is that the script still doesn’t work tho.

CleanPlayer is only called once whenever a new player is added, you need to wrap your code inside a CharacterAdded event for it to be executed each time a new character is added.

And how would I do that exactly?

You’re welcome to copy and paste your script here, I’m sure someone will implement the required fixes for you.

local Players = game:GetService(“Players”)
local IgnoreTeams = {game.Teams.Grey}
local function CleanPlayer(player)

for _,team in pairs(IgnoreTeams) do

if player.Team == team then return end
end

local character = player.Character or player.CharacterAdded:Wait()

if character then
	for _,characterInstance in ipairs(character:GetChildren()) do
		if characterInstance:IsA("Shirt") or characterInstance:IsA("Pants") then
			characterInstance:Destroy()
		end
	end
end
end
local function CleanPlayers()
for _,player in ipairs(Players:GetPlayers()) do
	CleanPlayer(player)
end
end
Players.PlayerAdded:Connect(function(Player)
CleanPlayer(Player)
end)

@Forummer I don’t think it is finding the character. Do you know why?