Script Not Show Player legs, and i don't find the reason

Hello Develepers, i have recently Made a Script which Turns the Player in to a rich Player character (for a Hangout Game where you can wear Outfits, If you click on a imagebutton. Everything works, but there IS one Thing which Looks very Bad, i Wanted to make the leg from the Player character Like this (Basic roblox R15 left leg):

But instead it Looks Like this:

IMG-20240821-WA0002

Idk what i did wrong, did you find anything what could Help🫤:

local replicatedStorage = game:GetService(ā€œReplicatedStorageā€)
local serverStorage = game:GetService(ā€œServerStorageā€)
local players = game:GetService(ā€œPlayersā€)
local assetService = game:GetService(ā€œAssetServiceā€)
local changeEvent = replicatedStorage:WaitForChild(ā€œChangeClothesAndAccessoriesā€)

In the ServerScriptService:

-- New clothing and accessories IDs
local newShirtId = 12024349249  -- Updated shirt image ID
local newPantsId = 11655943481  -- Updated pants image ID
local newHairId = 10793232653
local newAccessories = {
	4755273442,
	4904032037,
	8919560130,
	6238769080,
	10953838490,
	4960940411,
	10896124270,
	12872974883,
}
local newBundleId = 239
local equipmentToolId = 292969932 -- The ID of the equipment tool
local leftLegBundleId = 17873576184 -- The ID for the left leg

-- Function to remove old accessories
local function removeOldAccessories(character)
	-- Remove old accessories
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Accessory") then
			child:Destroy()
		end
	end

	-- Remove old tools
	for _, tool in pairs(character:GetChildren()) do
		if tool:IsA("Tool") then
			tool:Destroy()
		end
	end

	-- Remove old hair
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Hair then
			child:Destroy()
		end
	end

	-- Remove old shirts and pants
	local shirt = character:FindFirstChildOfClass("Shirt")
	if shirt then
		shirt:Destroy()
	end

	local pants = character:FindFirstChildOfClass("Pants")
	if pants then
		pants:Destroy()
	end
end

-- Function to replace the left leg
local function replaceLeftLeg(character)
	-- Remove the existing left leg
	local leftLegParts = {"LeftUpperLeg", "LeftLowerLeg", "LeftFoot"}
	for _, partName in ipairs(leftLegParts) do
		local part = character:FindFirstChild(partName)
		if part then
			part:Destroy()
		end
	end

	-- Add the new left leg from the bundle
	local success, legModel = pcall(function()
		return game:GetService("InsertService"):LoadAsset(leftLegBundleId)
	end)
	if success then
		local leg = legModel:FindFirstChild("inf15-Left-Leg")
		if leg then
			leg.Parent = character
		end
		legModel:Destroy()
	else
		warn("Failed to load left leg with ID: " .. tostring(leftLegBundleId))
	end
end

-- Function to add new clothes and accessories
local function addNewClothesAndAccessories(character, player)
	-- Replace the left leg
	replaceLeftLeg(character)

	-- Add new hair
	local success, hairModel = pcall(function()
		return game:GetService("InsertService"):LoadAsset(newHairId)
	end)
	if success then
		local hair = hairModel:FindFirstChildOfClass("Accessory")
		if hair then
			hair.Parent = character
		end
		hairModel:Destroy()
	else
		warn("Failed to load hair with ID: " .. tostring(newHairId))
	end

	-- Add new accessories
	for _, accessoryId in ipairs(newAccessories) do
		local success, accessoryModel = pcall(function()
			return game:GetService("InsertService"):LoadAsset(accessoryId)
		end)
		if success then
			local accessory = accessoryModel:FindFirstChildOfClass("Accessory")
			if accessory then
				accessory.Parent = character
			end
			accessoryModel:Destroy()
		else
			warn("Failed to load accessory with ID: " .. tostring(accessoryId))
		end
	end

	-- Add new tools from ServerStorage
	local vipToolsFolder = serverStorage:FindFirstChild("VIPTools")
	if vipToolsFolder then
		for _, tool in pairs(vipToolsFolder:GetChildren()) do
			if tool:IsA("Tool") then
				local clonedTool = tool:Clone()
				clonedTool.Parent = player.Backpack
			end
		end
	else
		warn("VIPTools folder not found in ServerStorage")
	end

	-- Add the specific equipment tool
	local success, toolModel = pcall(function()
		return game:GetService("InsertService"):LoadAsset(equipmentToolId)
	end)
	if success then
		local tool = toolModel:FindFirstChildOfClass("Tool")
		if tool then
			tool.Parent = player.Backpack
		end
		toolModel:Destroy()
	else
		warn("Failed to load equipment tool with ID: " .. tostring(equipmentToolId))
	end

	-- Change skin color to white
	for _, bodyPart in pairs(character:GetChildren()) do
		if bodyPart:IsA("BasePart") and bodyPart.Name ~= "Head" then
			bodyPart.BrickColor = BrickColor.new("Institutional white")
		end
	end
end

-- Function to apply new bundle
local function applyNewBundle(humanoid, bundleId)
	if bundleId then
		humanoid.RequiresNeck = false

		local function tryGet(context, object, funcName, ...)
			local success, result = pcall(object[funcName], object, ...)

			if success then
				return result
			else
				warn("Invalid", context .. ':', ..., "(Error:", result .. ')')
			end
		end

		local bundle
		local info = tryGet("BundleId", assetService, "GetBundleDetailsAsync", bundleId)

		if info then
			local id = 0

			for _, item in pairs(info.Items) do
				if item.Type == "UserOutfit" then
					id = item.Id
					break
				end
			end

			if id > 0 then
				bundle = tryGet("Bundle", players, "GetHumanoidDescriptionFromOutfitId", id)
			end
		end

		if bundle then
			humanoid:ApplyDescription(bundle)
		end
	end
end

-- Function to handle the RemoteEvent
local function onChangeClothesAndAccessories(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		applyNewBundle(humanoid, newBundleId)
		removeOldAccessories(character)
		addNewClothesAndAccessories(character, player)

		-- Add new shirt and pants after applying the bundle
		local newShirt = Instance.new("Shirt", character)
		newShirt.ShirtTemplate = "rbxassetid://" .. newShirtId

		local newPants = Instance.new("Pants", character)
		newPants.PantsTemplate = "rbxassetid://" .. newPantsId

		-- Make parts invisible
		local partsToHide = {"RightFoot", "RightLowerLeg", "RightUpperLeg", "Head"}
		for _, partName in ipairs(partsToHide) do
			local part = character:FindFirstChild(partName)
			if part then
				part.Transparency = 1
			end
		end

		-- Remove face
		local face = character.Head:FindFirstChildOfClass("Decal")
		if face then
			face:Destroy()
		end
	end
end

changeEvent.OnServerEvent:Connect(onChangeClothesAndAccessories)

Pls answer If you find something :pray:.

After doing some quick testing with your code, the issue comes down to how you get the parts of the new leg.
image

I cloned the legModel into ServerStorage once it was grabbed (since it did sucessfully load), and found that inf15-Left-Leg isn’t a valid child, which led to the leg disappearing.

1 Like

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