Alright so I think I’m going about this all wrong. Im sure theres a more streamlined way of doing this, but I’m unsure. This is what I have:
local PS = game:GetService("Players")
local CC = require(game.ReplicatedStorage:WaitForChild("Modules").CharacterConfig)
local function changeClothing(character, shirtID, pantsID)
print("Character added, remove clothing")
for _, item in pairs(character:GetChildren()) do
if item:IsA("Shirt") then
item.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
end
if item:IsA("Pants") then
item.PantsTemplate = "http://www.roblox.com/asset/?id="..pantsID
end
end
end
PS.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
task.wait(0.2)
if plr.Team.Name == "Prisoner" then
changeClothing(character, "7259669741", "230507724")
else if plr.Team.Name == "Police" then
changeClothing(character, "7259669741", "230507724")
end
end
end)
end)
is this the best way? If not then how?
EDIT: I know the clothing is the same on both cops and prisoners here, but its different in game.
At the moment if the character doesn’t have a Shirt or Pants, they’ll never get any team’s uniform. If this is undesirable, you’ll need to create a Shirt/Pants Instance for them, like so:
local PS = game:GetService("Players")
local CC = require(game.ReplicatedStorage:WaitForChild("Modules").CharacterConfig)
local function changeClothing(character, shirtID, pantsID)
print("Character added, remove clothing")
local shirt = character:FindFirstChildWhichIsA("Shirt")
if shirt then
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
else
shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
shirt.Parent = character
end
local pants = character:FindFirstChildWhichIsA("Pants")
if pants then
pants.PantsTemplate = "http://www.roblox.com/asset/?id="..pantsID
else
pants = Instance.new("Pants")
pants.PantsTemplate = "http://www.roblox.com/asset/?id="..pantsID
pants.Parent = character
end
end
PS.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
task.wait(0.2)
if plr.Team.Name == "Prisoner" then
changeClothing(character, "7259669741", "230507724")
else if plr.Team.Name == "Police" then
changeClothing(character, "7259669741", "230507724")
end
end
end)
end)