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

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

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

✓ 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)
	-- 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.

1 comment

0

Thank you so much!

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