✓ Accepted answer
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)
player.CharacterAppearanceLoaded:Connect(function(character)
if character:FindFirstChildOfClass("Shirt") then
character:FindFirstChildOfClass("Shirt").ShirtTemplate = shirtId
else
local shirt = Instance.new("Shirt")
shirt.Name = "Shirt"
shirt.ShirtTemplate = shirtId
shirt.Parent = character
end
if character:FindFirstChildOfClass("Pants") then
character:FindFirstChildOfClass("Pants").PantsTemplate = pantsId
else
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.
1 comment
Thank you so much!