I need an outfit to been only worn by people who are on a certain team (Slayers). But I don’t understand how to make this work, so that only players on a certain team will get the clothing.
Can somebody help me? I will greatly appreciate your scripts and suggestions!
Hi, so I used the solution from that topic you linked and it doesnt work for some reason:
local TeamClothes = {
Slayers = {
Shirt = "rbxassetid://5007827268", -- Example Shirt Asset ID for Slayers
Pants = "rbxassetid://5007837224" -- Example Pants Asset ID for Slayers
},
Demons = {
Shirt = "rbxassetid://1122334455", -- Example Shirt Asset ID for Demons
Pants = "rbxassetid://5544332211" -- Example Pants Asset ID for Demons
}
}
function addClothing(player, character)
repeat wait() until player:HasAppearanceLoaded()
local Shirt
local Pants
if not character:FindFirstChildOfClass("Shirt") then
Shirt = Instance.new("Shirt")
Shirt.Parent = character
else
Shirt = character:FindFirstChildOfClass("Shirt")
end
if not character:FindFirstChildOfClass("Pants") then
Pants = Instance.new("Pants")
Pants.Parent = character
else
Pants = character:FindFirstChildOfClass("Pants")
end
-- Apply clothing based on the player's team
for teamName, clothes in pairs(TeamClothes) do
if player.Team and player.Team.Name == teamName then
-- Apply the correct Shirt and Pants for the team
if Shirt then
Shirt.ShirtTemplate = clothes.Shirt
end
if Pants then
Pants.PantsTemplate = clothes.Pants
end
end
end
end
-- Ensure the clothing is added when the player joins and when their character is added.
game.Players.PlayerAdded:Connect(function(player)
if player.Character then
addClothing(player, player.Character) -- Apply clothing if the character is already loaded
end
player.CharacterAdded:Connect(function(character)
addClothing(player, character) -- Apply clothing when the character is added
end)
end)
It doesn’t work in or out of studio, and I’m not seeing errors in the output.
-- Define the team names and asset IDs
local teamName = "Slayers" -- Change this to your actual team name
local shirtId = "rbxassetid://5007827268" -- The ID of the shirt (use the Asset ID, not the URL)
local pantsId = "rbxassetid://5007837224" -- The ID of the pants (use the Asset ID, not the URL)
-- Function to change the player's outfit
local function changeOutfit(player)
-- Check if the player is on the specified team
if player.Team and player.Team.Name == teamName then
local character = player.Character
if character then
-- Make sure the character is fully loaded
local shirt = character:FindFirstChildOfClass("Shirt")
local pants = character:FindFirstChildOfClass("Pants")
-- If the player doesn't have the shirt or pants, create new ones
if not shirt then
shirt = Instance.new("Shirt")
shirt.Parent = character
end
if not pants then
pants = Instance.new("Pants")
pants.Parent = character
end
-- Set the Shirt and Pants IDs
shirt.ShirtTemplate = "rbxassetid://" .. shirtId
pants.PantsTemplate = "rbxassetid://" .. pantsId
end
end
end
-- Connect the function to the player added event
game.Players.PlayerAdded:Connect(function(player)
-- Ensure the character is added and fully loaded before applying the outfit
player.CharacterAdded:Connect(function(character)
changeOutfit(player)
end)
end)
-- Optional: Listen for changes in the player's team and update their outfit
game.Players.PlayerAdded:Connect(function(player)
player.TeamChanged:Connect(function()
changeOutfit(player)
end)
end)
I pretty much re-wrote this but try to see if it works:
local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")
local ClothesID = {
Slayers = { --Team name (has to be same as one under the teams instance)
Shirt = 5007827268, --The ID of the shirt
Pants = 5007837224 --The ID of the pants
},
Demons = {
Shirt = 1122334455,
Pants = 5544332211
}
}
local function FetchFit(AssetId:number, Parent:Instance)
local Succ, Result= pcall(InsertService.LoadAsset, InsertService, AssetId)
if not Succ then warn(Result) return end
local Child = Result:GetChildren()[1]
Child.Parent = Parent
Result:Destroy()
end
local function TeamChanged(Player:Player)
local Character = Player.Character
if not Character or not Player.Team then return end
local Team = Player.Team.Name
local ClothesData = ClothesID[Team]
if not ClothesData then return end
local Shirt = Character:FindFirstChildOfClass("Shirt")
local Pants = Character:FindFirstChildOfClass("Pants")
if Shirt then Shirt:Destroy() end
if Pants then Pants:Destroy() end
FetchFit(ClothesData["Shirt"], Character)
FetchFit(ClothesData["Pants"], Character)
end
for _, Team in game:GetService("Teams"):GetTeams() do
Team.PlayerAdded:Connect(TeamChanged)
end
Players.PlayerAdded:Connect(function(player: Player)
player.CharacterAppearanceLoaded:Connect(function(character: Model)
TeamChanged(player)
end)
end)
What this script does differently is that it deletes the users shirts and pants before giving them new ones
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local RED_TEAM_NAME = "Slayers"
local SHIRT_ID = 1111111111
local PANTS_ID = 2222222222
Players.PlayerAdded:Connect(function(player)
print("Player " .. player.Name .. " joined the game")
player.CharacterAdded:Connect(function(character)
-- Remove any existing shirts and pants
for _, child in ipairs(character:GetChildren()) do
if child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
local team = player.Team
if team and team.Name == RED_TEAM_NAME then
print(player.Name .. " is on the slayers team")
local shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "rbxassetid://" .. SHIRT_ID
shirt.Parent = character
local pants = Instance.new("Pants")
pants.PantsTemplate = "rbxassetid://" .. PANTS_ID
pants.Parent = character
else
print(player.Name .. " is not on the slayers team")
end
end)
end)
for _, player in Players:GetPlayers() do
print(player.Name .. " is already in the game")
player.CharacterAdded:Connect(function(character)
-- Remove any existing shirts and pants
for _, child in ipairs(character:GetChildren()) do
if child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
local team = player.Team
if team and team.Name == RED_TEAM_NAME then
print(player.Name .. " is on the slayers team")
local shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "rbxassetid://" .. SHIRT_ID
shirt.Parent = character
local pants = Instance.new("Pants")
pants.PantsTemplate = "rbxassetid://" .. PANTS_ID
pants.Parent = character
else
print(player.Name .. " is not on the slayers team")
end
end)
end
--bombaclat