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:
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
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.
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.
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.
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)