Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a shirt instance, or change a shirt id on a character?

Ok so now I have a serverscript inside of a part with the click detector and the id value. The instance is in the character, but doesn't display on the character.

local part = script.Parent
local detector = part.ClickDetector
local id = part.Id
clothingType = "Pants" --Change to "Pants" or "Shirt"

detector.MouseClick:Connect(function(player)
	if player.Buy.Value == true then
		
	else
		local char = workspace:FindFirstChild(player.Name)
		local findClothing = char:FindFirstChild(clothingType)
		if findClothing then
			findClothing:Destroy()
			if clothingType == "Shirt" then
			local newShirt = Instance.new("Shirt")
			newShirt.Name = "Shirt"
			newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..id.Value
			newShirt.Parent = char
			elseif clothingType == "Pants" then
			local newPants = Instance.new("Pants")
			newPants.Name = "Pants"
			newPants.PantsTemplate = "http://www.roblox.com/asset/?id="..id.Value
			newPants.Parent = char
			end
		else
			if clothingType == "Shirt" then
			local newShirt = Instance.new("Shirt")
			newShirt.Name = "Shirt"
			newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..id.Value
			newShirt.Parent = char
			elseif clothingType == "Pants" then
			local newPants = Instance.new("Pants")
			newPants.Name = "Pants"
			newPants.PantsTemplate = "http://www.roblox.com/asset/?id="..id.Value
			newPants.Parent = char
			end
		end
	end
end)

6 comments

0

er, whats your issue here?

0

well, you can get the character directly from the player instance (player.Character). hope that helps

0

try using "rbxassetid://[id]" instead of "http://www.roblox.com/asset/?id=[id]"

0

i tried that it didnt work

0

even tried insertservice

0

the issue is that the clothes wont show up

1 answer

✓ Accepted answer

Explanation

The issue isn't with your script, but with what you place into the ID value. When a piece of clothing is created, there are actually two assets created. Not only is your clothing (in the form of an XML file) uploaded, but an image of your clothing is also uploaded.

Whenever you add clothes to a character in-game, Roblox expects you to place the image ID into the Template property, which is why it errors when you use the clothing ID. It's attempting to read the XML file as an image at runtime, which ends up throwing an error.

Solution

Before doing any of this, make sure to install BTRoblox.

In order to get an image ID from a piece of clothing, click on the piece of clothing you want to add into your game. Right next to the name of the clothing, there should be an icon that resembles a photograph. Clicking on it should send you to the library page for the image, which you can then get the ID of from the URL.

EDIT: I know this answer is not about scripting, but it's still some important information that not many people know about.

EDIT 2: Here's proof your script works. I used the same script as shown in the question, and the only thing I changed was the ID value.

2 comments

0

I don't see the icon anywhere. Anyway I could get some help

0

Did you install BTRoblox? The icon should be to the right of the name. It looks like an image, and when you click on it you should be taken to the page for the image.

This discussion is preserved as it was. New answers, comments, and votes are closed.