Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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)
0
er, whats your issue here? RAFA1608 543 — 4y
0
well, you can get the character directly from the player instance (player.Character). hope that helps RAFA1608 543 — 4y
0
try using "rbxassetid://[id]" instead of "http://www.roblox.com/asset/?id=[id]" RAFA1608 543 — 4y
0
i tried that it didnt work ReallyUnikatni 68 — 4y
View all comments (2 more)
0
even tried insertservice ReallyUnikatni 68 — 4y
0
the issue is that the clothes wont show up ReallyUnikatni 68 — 4y

1 answer

Log in to vote
1
Answered by
y3_th 176
4 years ago
Edited 4 years ago

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.

0
I don't see the icon anywhere. Anyway I could get some help ReallyUnikatni 68 — 4y
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. y3_th 176 — 4y
Ad

Answer this question