Help creating an automatic shirt applier/creator!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I’d like to create a GUI for that when I enter a ItemID, it applies that ID to my character shirt, or if I don’t have one, creates one for me and applies it. The GUI has 3 buttons hence why it may seem weird.
  2. What is the issue?
    It just refuses to apply the shirt on me, but it creates the shirt.
  3. What solutions have you tried so far?
    I’ve tried using ChatGPT to rewrite my script and make it work, but that was useless.
game.ReplicatedStorage.Apply.OnServerEvent:Connect(function(player, input, _type)
	print("Received event for player:", player.Name, "Input:", input, "Type:", _type)

	if _type == "S" then
		local character = player.Character or player.CharacterAdded:Wait()

		if not character:FindFirstChild("Shirt") then
			-- Create a new shirt
			local shirt = Instance.new("Shirt")
			-- Customize the shirt as needed, for example:
			shirt.Name = "Shirt"
			shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. input

			-- Attach the shirt to the player's character
			shirt.Parent = character
			print("Shirt created and applied to", player.Name)
		else
			character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. input
			print("Shirt updated for", player.Name)
		end
	else
		print("Invalid type:", _type)
	end


end)

image

Try converting the input variable to a string to allow it to concatenate without error?:

if _type == "S" then
		local character = player.Character or player.CharacterAdded:Wait()

		if not character:FindFirstChild("Shirt") then
			-- Create a new shirt
			local shirt = Instance.new("Shirt")
			-- Customize the shirt as needed, for example:
			shirt.Name = "Shirt"
			shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. tostring(input)

			-- Attach the shirt to the player's character
			shirt.Parent = character
			print("Shirt created and applied to", player.Name)
		else
			character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. tostring(input)
			print("Shirt updated for", player.Name)
		end
	else
		print("Invalid type:", _type)
	end

You could also set the variable type for your input in the parameters as a string to ensure the value being sent, and return end or do any other thing that you wish if the input is anything but a string

game.ReplicatedStorage.Apply.OnServerEvent:Connect(function(player, input: string, _type)
	print("Received event for player:", player.Name, "Input:", input, "Type:", _type)

    if type(input) ~= string then return end -- or whatever else you want to do

-- next lines

Sorry lol I’m quite new to scripting. Hope you find a solution though!

It doesn’t work.
I’ve tried modifying the script a bit, and obviously using the original, but it just refuses :confused:

Alright so I’ve been experimenting and I think there is another way to do this.

This is using the Humanoid’s :ApplyDescription() and :GetAppliedDescription() methods.
Humanoid Documentation here

I have created a script in the ServerScriptService that references a rig in the workplace which applies a shirt with a specific shirt id to the character, like so:

local id = 1240513975

local hum = game.Workspace.Rig.Humanoid

-- creating a new HumanoidDescription from scratch
local testDescription: HumanoidDescription = hum:GetAppliedDescription() 

-- applied our modified description with a set shirt id
testDescription.Shirt = id
hum:ApplyDescription(testDescription)

You can even find HumanoidDescriptions in every Rig:
Screenshot 2023-12-03 163806

With many properties we can edit of a character, including clothing and accessories:
Screenshot 2023-12-03 163814

And now when the script is run it applies the shirt id onto the fresh rig:

It even created a new Shirt instance to the character rig as my avatar previously had no clothing assets equipped.

Try implementing something like the example I provided in your project!

Thanks so much, it works perfectly! I appreciate it.

1 Like

No worries, good luck with your project!

1 Like

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