How to change a character's "bundle"

Since I’m not a professional scripter I didn’t write the code. So I’m making a leaderboard with the top 1 player sitting on it. It works but not how I want it to work. It changes the dummy’s shirt, pants, tshirt etc but it doesn’t change the player’s “bundle” if you know what I mean. I was searching different methods for an hour or two but they made the leaderboard not work.
image

The leaderboard script (not pasting the whole thing cause this is the only part that matters):

local dss = game:GetService("DataStoreService")
local ds = dss:GetOrderedDataStore("AllTime1")
local Loader = require(script.Loader)
local tab = workspace.Dummy

local function Handler()
	local Success, Err = pcall(function()
		local Data = ds:GetSortedAsync(false, 100)
		local Page = Data:GetCurrentPage()
				
		local names = {}
		for Rank, Data in ipairs(Page) do
			local Name = Data.key
			local Amount = Data.value
			local NewObj = script.Template:Clone()
			NewObj.PlrName.Text = Name
			local retrievedValue = Data.value ~= 0 and (1.0000001 ^ Data.value) or 0
			if game.Players:FindFirstChild(Name) then
				names[Name] = Rank
			end
			if Rank == 1 then
				local userId
				local success, err = pcall(function()
					userId = game.Players:GetUserIdFromNameAsync(Name)
				end)
				if(not success) then
					print("Something went wrong with the statues")
					warn(err)
				else
					spawn(function()
						Loader:ClearCharacter(tab)
						wait()
						Loader:LoadCharacter(userId, tab)
					end)
			end
			NewObj.Money.Text = format(retrievedValue)
			NewObj.Rank.Text = "#"..Rank
			NewObj.Parent = script.Parent
		end
		for i, v in pairs(game.Players:GetChildren()) do
			if names[v.Name] then
				local char = v.Character or v.CharacterAdded:Wait()
				giveRank(char, names[v.Name])
			else
				local char = v.Character or v.CharacterAdded:Wait()
				removeRank(char)
			end
		end
	end)
end

Module script inside the leaderboard script:

local loader = {}

function loader:LoadCharacter(userId, doll)
	local info
	local success, err = pcall(function()
		info = game.Players:GetCharacterAppearanceAsync(userId)
		doll.Name = game.Players:GetNameFromUserIdAsync(userId)
	end)
	if(success) then
		repeat wait() until info
		local shirt = info:WaitForChild("Shirt",3)
		local pants = info:WaitForChild("Pants",3)
		local tshirt = info:WaitForChild("ShirtGraphic",3)
		if(shirt) then shirt.Parent = doll end
		if(pants) then pants.Parent = doll end
		if(tshirt) then tshirt.Parent = doll end
		for i,v in pairs(info:GetChildren()) do
			if(v:IsA("Accessory") or v:IsA("BodyColors")) then
				v.Parent = doll
			elseif(v:IsA("NumberValue")) then
				local hum = doll:FindFirstChildWhichIsA("Humanoid")
				local value = hum:FindFirstChild(v.Name)
				if(value) then
					value.Value = v.Value
				else
					v.Parent = hum
				end
			elseif(v:IsA("SpecialMesh")) then
				local head = doll:FindFirstChild("Head")
				if(head) then
					local mesh = head:FindFirstChildWhichIsA("SpecialMesh")
					if(mesh) then
						mesh:Destroy()
						v.Parent = head
						for i,v in pairs(v:GetChildren()) do
							local attach = head:FindFirstChild(v.Name)
							if(attach) then
								if(attach:IsA("Attachment")) then
									attach.Position = v.Value
								end
							end
						end
					end
				end
			elseif(v:IsA("Decal")) then
				if(v.Name == "face") then
					local head = doll:FindFirstChild("Head") 
					local dec = head:FindFirstChildWhichIsA("Decal")
					if(dec) then
						dec.Texture = v.Texture
					end
				end
			end
		end
		info:Destroy()
	else
		print("Error ocurred while loading character")
		warn(err)
	end
end

function loader:ClearCharacter(doll)
	for i,v in pairs(doll:GetDescendants()) do
		if(v:IsA("Accessory") or v:IsA("BodyColors") or v:IsA("NumberValue") or v:IsA("Shirt") or v:IsA("Pants") or v:IsA("ShirtGraphic")) then
			v:Destroy()
		elseif(v:IsA("Decal")) then
			v.Texture =  "rbxasset://textures/face.png"
		elseif(v:IsA("BasePart")) then
			v.BrickColor = BrickColor.new("Medium stone grey")
		end
		doll.Name = ""
	end
end
return loader

Hello, I think to this work you should use method Humanoid:ApplyDescription(userId). I recommend to change dummy look via HumanoidDescription.

HumanoidDescription is more like list of accesories which wears your character. It defines: Accesories, Animation, BodyColors, BodyParts, Clothes and Scale.

To change dummy’s character apperance via HumanoidDescription, you need firstly to get Humanoid of Dummy/Character and later apply to it your custom HumanoidDescription.

I’ll show you example code:

local Players = game:GetService("Players"); -- Players Service

local Dummy = workspace.Rig; -- your dummy/rig
local DummyHumanoid = Dummy:WaitForChild("Humanoid"); -- Dummy's Humanoid

local ClickDetector = workspace.Part.ClickDetector; -- some ClickDetector

ClickDetector.MouseClick:Connect(function(plr) -- function 
	local plr_humDes = Players:GetHumanoidDescriptionFromUserId(plr.UserId); -- getting humanoidDescription of player by their userId
	if(plr_humDes)then -- if HumanoidDescription exists
		DummyHumanoid:ApplyDescription(plr_humDes); -- applying player's humanoid description to dummy/rig
	end
end)

This code basically making dummy’s appearance change to player’s appearance when you clicked on a part.

I’m leaving you some links:
HumanoidDescription
Character Appearance

I hope this will help.

2 Likes

Ah yes it works perfectly fine. Thank you very much for taking your time and helping me!

2 Likes

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