local ShirtId = 1335655058
local PantsId = 3070502453
function ChangeOutfit(Player)
for _, cloth in pairs (Player.Character:GetChildren()) do
if cloth:IsA("Shirt") or cloth:IsA("Pants") then
cloth:Destroy()
end
end
local Shirt = Instance.new("Shirt", Player.Character)
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..ShirtId -1
local Pants = Instance.new("Pants", Player.Character)
Pants.PantsTemplate = "http://www.roblox.com/asset/?id="..PantsId -1
end
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
if (Player.Character.HumanoidRootPart.Position - script.Parent.Position).Magnitude < 15 then
ChangeOutfit(Player)
end
end)
I wouldn’t destroy the shirt and pants though, i would just change the Shirt/PantsTemplate but it’s up to you, it removed your clothes because you destroyed the shirt and pants
You can’t reliably grab a shirt/pants template through this method, templates can reasonably be anywhere from 1-200 less than the ID itself.
You would need to use an API endpoint to fetch the template ID from the shirt ID, the only issue is I’m not aware of any open-source endpoints to do this and I myself don’t have the know-how to produce one for you either.
Best I can do is just supply you with an updated code with accurate shirt/pants template IDs:
local ShirtId = 1335655056
local PantsId = 3070502409
function ChangeOutfit(Player)
if Player.Character:FindFirstChild("Shirt") then
local Shirt = Player.Character.Shirt
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..ShirtId
end
if Player.Character:FindFirstChild("Pants") then
local Pants = Player.Character.Pants
Pants.PantsTemplate = "http://www.roblox.com/asset/?id="..PantsId
end
end
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
if (Player.Character.HumanoidRootPart.Position - script.Parent.Position).Magnitude < 15 then
ChangeOutfit(Player)
end
end)