Shirts and Pants not changing

Hey everybody.

I am working on a character customization system for my roleplay game. First things first - I decided to tackle shirts and pants as I thought it’d be simple.

Lord almighty, it isn’t.

-- // Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- // Variables
local Main = script.Parent :: Frame
local Viewport = Main.Viewport :: ViewportFrame

local Dummy = Viewport:WaitForChild("Dummy") :: Model
local shirt = Dummy:FindFirstChildOfClass("Shirt")
local pants = Dummy:FindFirstChildOfClass("Pants") 

-- // Accessories
local AccessoriesFolder = ReplicatedStorage:WaitForChild("Accessories") :: Folder
local ClothingModule = require(AccessoriesFolder:FindFirstChild("Clothing"))
	
local choices = {}

-- // Code

-- // Checks
if not ClothingModule then
	warn("Could not get clothing module!")
end
----

function getClothing(category: string) : {string}
	if ClothingModule[category] then
		return ClothingModule[category]
	end
	return {}
end

function getItems(category: string) : {Instance}
	local folder = AccessoriesFolder:FindFirstChild(category)
	if folder then
		return folder:GetChildren()
	end
	return {}
end

function getItemList(category: string) : {any}
	if category == "Shirt" or category == "Pants" then
		return getClothing(category)
	else
		return getItems(category)
	end
end

function updatePreview(category: string)
	local items = getItemList(category)
	if #items == 0 then return warn("List of items is empty!") end

	local selectedIndex = choices[category]
	if not selectedIndex then return warn("Invalid selection index!") end

	local selected = items[selectedIndex]
	if not selected then return warn("Could not get selected item in Character Customizer!") end
	

	if category == "Shirt" then
		if not shirt then
			shirt = Instance.new("Shirt")
			shirt.Parent = Dummy
		end
		local id = ClothingModule.Shirt[selectedIndex]
		if shirt and id then
			shirt.ShirtTemplate = id
		end
		return
	elseif category == "Pants" then
		if not pants then
			pants = Instance.new("Pants")
			pants.Parent = Dummy
		end
		local id = ClothingModule.Pants[selectedIndex]
		if pants and id then
			pants.PantsTemplate = id
		end
		return
	end


	for _, accessory in Dummy:GetChildren() do
		if accessory:IsA("Accessory") and accessory:GetAttribute("Category") == category then
			accessory:Destroy()
		end
	end

	local newAccessory = selected
	if newAccessory then
		local clone = newAccessory:Clone()
		clone.Parent = Dummy
	end
end

for _, frame in pairs(Main:GetDescendants()) do
	if frame:IsA("Frame") and frame:GetAttribute("Category") then
		local category = frame:GetAttribute("Category") :: string
		choices[category] = 1
		
		frame.Back.MouseButton1Click:Connect(function()
			local items = getItemList(category)
			choices[category] -= 1
			if choices[category] < 1 then
				choices[category] = #items
			end
			updatePreview(category)
		end)
		
		frame.Forward.MouseButton1Click:Connect(function()
			local items = getItemList(category)
			choices[category] += 1
			if choices[category] > #items then
				choices[category] = 1
			end
			updatePreview(category)
		end)
		
	end
end

Here’s the funny thing - the IDs are getting gotten. The dummy exists, every single required variable exists. But when I try changing the ID - it remains blank. WHY?!

The dummy is in a viewport.

I literally have no idea how to stop this, I tried both the full URL and rbxassetid, literally NOTHING works!! I am wasting my time and sanity just for this dumb thing to work.

If you’re curious, here’s my module.

return {
	
	Shirt = {
		"rbxassetid://6067501477",
		"rbxassetid://4996763405",
	},
	
	Pants = {
		"rbxassetid://6067504287",
		"rbxassetid://7581780596"
	}
	
}

The rbxassetid’s in your module are not actual asset ids
I tested the first one under shirt and the ID changes after updating the shirt manually
image

In short, you need to convert your existing ids to asset ids first, then it should work. You can do that like how I did it above.

2 Likes

what do you mean exactly? as in convert them to numbers?

Hey. So I figured out the issue.
Finally understood this after your message and another devforum post.

Another explanation for people with my issue:
Yeah you gotta copy the ID FROM THE TEMPLATE ITSELF, which appears after you INSERT THE ID.

Or with the BetterRoblox extension for those that have it - you go to the shirt page and click the little picture icon.


Which in turn takes you to the template page.

Copy the ID of THIS ASSET.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.