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

Clothing not loading in studio.When I change clothing its not loading?

Asked by 5 years ago

When I changed the shirt/pants template id, the clothing is not showing up. Am i doing something wrong?

shirtid = "http://www.roblox.com/asset/?id=1619390082"
pantsid = "http://www.roblox.com/asset/?id=1619390302"

game.Players.PlayerAdded:connect(function(player)
    local char = workspace:WaitForChild(player.Name)
    char.Shirt.ShirtTemplate = shirtid
    char.Pants.PantsTemplate = pantsid
end)

1 answer

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
5 years ago
Edited 5 years ago

This is because of the age-old structure of Roblox where the actual shirt/pants are different from their textures. Basically, you need to go to the page of the shirt or pants on the Roblox website, look at its URL, and subtract 1 from the numbers in its URL until you find the corresponding texture. Once you find it, use that ID of the newly-founded texture's page in its URL as textures in your game.

Now, for the code, firstly, make sure to use local variables. It is in the nature of Lua that local variables are indexed faster than global ones, and even if there is a negligible performance difference, you should still use them because it's good practice to do so. Secondly, you should really take advantage of the fact that you can :Connect() functions to events. There is an event of the Player object called CharacterAppearanceAdded. It fires whenever the player's character appearance has loaded. Lastly, we need to take into account that the player may not be wearing any shirt or pants, so we need to create new Shirt or Pants objects to do so.

Combining all this information, we can come up with something like this:

local shirtId = "http://www.roblox.com/asset/?id=1619390075"
local pantsId = "http://www.roblox.com/asset/?id=1619390298"

game.Players.PlayerAdded:Connect(function(player)
    -- Execute the code only when the player's character appearance has loaded
    player.CharacterAppearanceLoaded:Connect(function(character)
        -- Change any existing shirt
        if character:FindFirstChildOfClass("Shirt") then
            character:FindFirstChildOfClass("Shirt").ShirtTemplate = shirtId
        else
            -- Put on a new shirt
            local shirt = Instance.new("Shirt")
            shirt.Name = "Shirt"
            shirt.ShirtTemplate = shirtId
            shirt.Parent = character
        end

        -- Change any existing pants
        if character:FindFirstChildOfClass("Pants") then
            character:FindFirstChildOfClass("Pants").PantsTemplate = pantsId
        else
            -- Put on new pants
            local pants = Instance.new("Pants")
            pants.Name = "Pants"
            pants.PantsTemplate = pantsId
            pants.Parent = character
        end
    end)
end)

I have gone through the trouble of subtracting 1 from the URL of your shirt and pants to find their textures for you, but remember that you'll have to do that every time you want to use shirts/pants/decals in-game.

0
Thank you so much! OnlineSaiyan 28 — 5y
Ad

Answer this question