So IDk what is wrong with this code but

local Plugin = plugin
local Toolbar = Plugin:CreateToolbar("Rig Controller")
local Button = Toolbar:CreateButton("Add Item", "Open Item Inserter UI.", "rbxassetid://4458874645")
local Button2 = Toolbar:CreateButton("Color", "Sets a rigs color.", "rbxassetid://9011713759")
local Button3 = Toolbar:CreateButton("Outfit", "Change the outfit.", "rbxassetid://85502241059648")
local Selection = game:GetService("Selection")

local WidgetInfo = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,
	false,
	false,
	300,
	200,
	300,
	200
)

local Widget = Plugin:CreateDockWidgetPluginGui("ItemInserter", WidgetInfo)
Widget.Title = "Item Inserter"

local UI = Instance.new("Frame")
UI.Size = UDim2.new(1, 0, 1, 0)
UI.BackgroundColor3 = Color3.fromRGB(83, 83, 83)
UI.Parent = Widget

local TextBoxID = Instance.new("TextBox")
TextBoxID.Size = UDim2.new(0.9, 0, 0.2, 0)
TextBoxID.Position = UDim2.new(0.05, 0, 0.1, 0)
TextBoxID.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxID.PlaceholderText = "Enter Item ID"
TextBoxID.Parent = UI
TextBoxID.Text = ""
TextBoxID.TextWrapped = true

local TextBoxTexture = Instance.new("TextBox")
TextBoxTexture.Size = UDim2.new(0.9, 0, 0.2, 0)
TextBoxTexture.Position = UDim2.new(0.05, 0, 0.4, 0)
TextBoxTexture.PlaceholderText = "Enter Texture ID (Optional)"
TextBoxTexture.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxTexture.Parent = UI
TextBoxTexture.Text = ""
TextBoxTexture.TextWrapped = true

local InsertButton = Instance.new("TextButton")
InsertButton.Size = UDim2.new(0.9, 0, 0.2, 0)
InsertButton.Position = UDim2.new(0.05, 0, 0.7, 0)
InsertButton.Text = "Add Item"
InsertButton.Parent = UI

local function InsertItem()
	local ID = tonumber(TextBoxID.Text)
	local TextureID = tonumber(TextBoxTexture.Text)

	if ID then
		local NewItem = game:GetService("InsertService"):LoadAsset(ID)

		if TextureID then
			for _, Part in ipairs(NewItem:GetChildren()) do
				if Part:IsA("Accessory") then
					local Mesh = Part:FindFirstChild("Handle") and Part.Handle:FindFirstChild("SpecialMesh")
					if Mesh then
						local Texture = game:GetService("InsertService"):LoadAsset(TextureID)

						for E, Dec in ipairs(Texture:GetChildren()) do
							if Dec:IsA("Decal") then
								Mesh.TextureId = Dec.Texture
							end
						end

						Texture:Destroy()
						break
					end
				end
			end
		end

		local Selected = Selection:Get()
		if Selected[1] and Selected[1]:FindFirstChild("Humanoid") then
			for _, Part in ipairs(NewItem:GetChildren()) do
				if Part:IsA("Accessory") then
					Part.Parent = Selected[1]
					break
				end
			end
			NewItem:Destroy()
		else
			NewItem.Parent = game.Workspace
		end
	else
		warn("Invalid ID")
	end
end

InsertButton.MouseButton1Click:Connect(InsertItem)
Button.Click:Connect(function()
	Widget.Enabled = not Widget.Enabled
	TextBoxID.Text = ""
	TextBoxTexture.Text = ""
end)

local ColorWidget = Plugin:CreateDockWidgetPluginGui("ColorSetter", WidgetInfo)
ColorWidget.Title = "Set Color"
ColorWidget.Enabled = false

local ColorUI = Instance.new("Frame")
ColorUI.Size = UDim2.new(1, 0, 1, 0)
ColorUI.BackgroundColor3 = Color3.fromRGB(83, 83, 83)
ColorUI.Parent = ColorWidget

local ColorRow = Instance.new("Frame")
ColorRow.Size = UDim2.new(0.9, 0, 0.2, 0)
ColorRow.Position = UDim2.new(0.05, 0, 0.05, 0)
ColorRow.BackgroundTransparency = 1
ColorRow.Parent = ColorUI

local TextBoxR = Instance.new("TextBox")
TextBoxR.Size = UDim2.new(0.3, 0, 1, 0)
TextBoxR.Position = UDim2.new(0, 0, 0, 0)
TextBoxR.PlaceholderText = "R: 0-255"
TextBoxR.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxR.Parent = ColorRow
TextBoxR.Text = ""
TextBoxR.TextWrapped = true

local TextBoxG = Instance.new("TextBox")
TextBoxG.Size = UDim2.new(0.3, 0, 1, 0)
TextBoxG.Position = UDim2.new(0.35, 0, 0, 0)
TextBoxG.PlaceholderText = "G: 0-255"
TextBoxG.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxG.Parent = ColorRow
TextBoxG.Text = ""
TextBoxG.TextWrapped = true

local TextBoxB = Instance.new("TextBox")
TextBoxB.Size = UDim2.new(0.3, 0, 1, 0)
TextBoxB.Position = UDim2.new(0.7, 0, 0, 0)
TextBoxB.PlaceholderText = "B: 0-255"
TextBoxB.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxB.Parent = ColorRow
TextBoxB.Text = ""
TextBoxB.TextWrapped = true

local SetColorButton = Instance.new("TextButton")
SetColorButton.Size = UDim2.new(0.9, 0, 0.2, 0)
SetColorButton.Position = UDim2.new(0.05, 0, 0.5, 0)
SetColorButton.Text = "Set Color"
SetColorButton.Parent = ColorUI

Button2.Click:Connect(function()
	ColorWidget.Enabled = not ColorWidget.Enabled
	TextBoxR.Text = ""
	TextBoxG.Text = ""
	TextBoxB.Text = ""
end)

local ColorMode = "RGB"

local ToggleModeButton = Instance.new("TextButton")
ToggleModeButton.Size = UDim2.new(0.9, 0, 0.2, 0)
ToggleModeButton.Position = UDim2.new(0.05, 0, 0.7, 0)
ToggleModeButton.Text = "Switch to Hex"
ToggleModeButton.Parent = ColorUI

local TextBoxHex = Instance.new("TextBox")
TextBoxHex.Size = UDim2.new(0.9, 0, 0.2, 0)
TextBoxHex.Position = UDim2.new(0.05, 0, 0.05, 0)
TextBoxHex.PlaceholderText = "Enter Hex Code (#RRGGBB)"
TextBoxHex.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
TextBoxHex.Parent = ColorUI
TextBoxHex.Text = ""
TextBoxHex.TextWrapped = true
TextBoxHex.Visible = false

ToggleModeButton.Activated:Connect(function()
	if ColorMode == "RGB" then
		ColorMode = "Hex"
		TextBoxR.Visible = false
		TextBoxG.Visible = false
		TextBoxB.Visible = false
		TextBoxHex.Visible = true
		ToggleModeButton.Text = "Switch to RGB"
	else
		ColorMode = "RGB"
		TextBoxR.Visible = true
		TextBoxG.Visible = true
		TextBoxB.Visible = true
		TextBoxHex.Visible = false
		ToggleModeButton.Text = "Switch to Hex"
	end
end)

SetColorButton.Activated:Connect(function()
	local Color
	if ColorMode == "RGB" then
		local R = math.clamp(tonumber(TextBoxR.Text), 0, 255)
		local G = math.clamp(tonumber(TextBoxG.Text), 0, 255)
		local B = math.clamp(tonumber(TextBoxB.Text), 0, 255)
		if R and G and B then
			Color = Color3.fromRGB(R, G, B)
		end
	else
		local Hex = TextBoxHex.Text:gsub("#", "")
		if #Hex == 6 then
			local R = tonumber(Hex:sub(1, 2), 16)
			local G = tonumber(Hex:sub(3, 4), 16)
			local B = tonumber(Hex:sub(5, 6), 16)
			if R and G and B then
				Color = Color3.fromRGB(R, G, B)
			end
		end
	end

	if Color then
		local Selected = Selection:Get()
		if Selected[1] and Selected[1]:FindFirstChild("Humanoid") then
			local BodyBind = Selected[1]:FindFirstChild("Body Colors")
			if BodyBind then
				BodyBind.TorsoColor3 = Color
				BodyBind.HeadColor3 = Color
				BodyBind.LeftArmColor3 = Color
				BodyBind.LeftLegColor3 = Color
				BodyBind.RightArmColor3 = Color
				BodyBind.RightLegColor3 = Color
			end
		end
	end
end)

local ClothesWidget = Plugin:CreateDockWidgetPluginGui("ClothesSetter", WidgetInfo)
ClothesWidget.Title = "Set Clothes"
ClothesWidget.Enabled = false

local ClothesUI = Instance.new("Frame")
ClothesUI.Size = UDim2.new(1, 0, 1, 0)
ClothesUI.BackgroundColor3 = Color3.fromRGB(83, 83, 83)
ClothesUI.Parent = ClothesWidget

local ShirtTextBox = Instance.new("TextBox")
ShirtTextBox.Size = UDim2.new(0.9, 0, 0.2, 0)
ShirtTextBox.Position = UDim2.new(0.05, 0, 0.1, 0)
ShirtTextBox.PlaceholderText = "Enter Shirt ID"
ShirtTextBox.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
ShirtTextBox.Parent = ClothesUI
ShirtTextBox.Text = ""
ShirtTextBox.TextWrapped = true

local PantsTextBox = Instance.new("TextBox")
PantsTextBox.Size = UDim2.new(0.9, 0, 0.2, 0)
PantsTextBox.Position = UDim2.new(0.05, 0, 0.4, 0)
PantsTextBox.PlaceholderText = "Enter Pants ID"
PantsTextBox.PlaceholderColor3 = Color3.new(0.278431, 0.278431, 0.278431)
PantsTextBox.Parent = ClothesUI
PantsTextBox.Text = ""
PantsTextBox.TextWrapped = true

local SetClothesButton = Instance.new("TextButton")
SetClothesButton.Size = UDim2.new(0.9, 0, 0.2, 0)
SetClothesButton.Position = UDim2.new(0.05, 0, 0.7, 0)
SetClothesButton.Text = "Set Clothes"
SetClothesButton.Parent = ClothesUI

Button3.Click:Connect(function()
	ClothesWidget.Enabled = not ClothesWidget.Enabled
	ShirtTextBox.Text = ""
	PantsTextBox.Text = ""
end)

SetClothesButton.Activated:Connect(function()
	local Shirt = tonumber(ShirtTextBox.Text)
	local Pants = tonumber(PantsTextBox.Text)
	local Selected = Selection:Get()
	
	if Selected[1] and Selected[1]:FindFirstChild("Humanoid") then
		if Shirt then
			for I, item in ipairs(Selected[1]:GetChildren()) do
				if item:IsA("Shirt") then
					item:Destroy()
					break
				end
				

				local NewShirt = game:GetService("InsertService"):LoadAsset(Shirt)

				for _, Shirts in ipairs(NewShirt:GetChildren()) do
					if Shirts:IsA("Shirt") then
						Shirts.Parent = Selected[1]
						break
					end
				end

				NewShirt:Destroy()
			end
		end
		
		if Pants then
			for I, item in ipairs(Selected[1]:GetChildren()) do
				if item:IsA("Pants") then
					item:Destroy()
				end
			end
			

			local NewShirt = game:GetService("InsertService"):LoadAsset(Pants)

			for _, Shirts in ipairs(NewShirt:GetChildren()) do
				if Shirts:IsA("Pants") then
					Shirts.Parent = Selected[1]
					break
				end
			end

			NewShirt:Destroy()

		end
	end
end)

Not exactly sure what is wrong with it??? Am I missing something?

1 Like