Changing clothes script not working

I know there’s other topics like this, but they don’t work.

I’m working on a city game, and I made a script that changes your team and changes your clothes that correspond with it, however when I change the clothes, the ID changes, but the clothes don’t show, making the player naked, which I do not want.

I tried literally everything, but to no avail.

Thanks for helping.

local teams = game.Teams
local prompt = script.Parent

local outsiderspawn = workspace.OutsiderSpawn

local ShirtTemplate = 6537417802
local PantsTemplate = 1908558576

prompt.Triggered:Connect(function(player)
	local char = player.Character
	
	player.Team = teams.Outsider
	
	char.HumanoidRootPart.Position = outsiderspawn.Position
	wait(0.5)
	for i, v in pairs(char:GetChildren()) do
		if v.Name == "Shirt" or v.Name == "Pants" then
			v:Destroy()
		end
	end
	local shirt = Instance.new("Shirt", char)
	local pants = Instance.new("Pants", char)
	
	shirt.ShirtTemplate = 6537417802
	pants.PantsTemplate = 1908558576
end)
1 Like

try this:

local teams = game.Teams
local prompt = script.Parent

local outsiderspawn = workspace.OutsiderSpawn

local shirtTemplate = "rbxassetid://6537417802"
local pantsTemplate = "rbxassetid://1908558576"

prompt.Triggered:Connect(function(player)
	local char = player.Character
	
	player.Team = teams.Outsider
	
	char.HumanoidRootPart.Position = outsiderspawn.Position
	wait(0.5)
	for i, v in pairs(char:GetChildren()) do
		if v.Name == "Shirt" or v.Name == "Pants" then
			v:Destroy()
		end
	end
	local shirt = Instance.new("Shirt", char)
	local pants = Instance.new("Pants", char)
	
	shirt.ShirtTemplate = shirtTemplate
	pants.PantsTemplate = pantsTemplate
end)
1 Like

If this helps you, this is inside a model.

instead of destroying the shirt and pants, maybe try changing just their templates instead
check if it’s a shirt, then change the shirtTemplate, else if it’s a pant, then change the pantsTemplate

I did, same result. However, when I manually change it in game, the clothes show??

Nevermind, I solved it. Just copy the ID when you test it and copy in the string, thanks for helping tho.

2 Likes

you’re welcome :grin: (extra chars)