How do I use ApplyDescription()

I’m trying to make an animation game where you can choose the avatars for the animation but I can’t find a way to use ApplyDescription() without it returning an error such as “Invalid argument: expected ‘HumanoidDescription’, got Instance”.

Local script in StarterGui:

script.Parent.MouseButton1Click:Connect(function()
	local input = script.Parent.Parent.InputBox
	local animationsFolder = game.ReplicatedStorage.Animations
	local dummy = workspace.R6
	local applyDescRemote = game.ReplicatedStorage.Events.applyDescRemote
	local humanoid = dummy.Humanoid

	-- Get the username from the input box
	local username = input.Text

	-- Use the Roblox API to get the userId from the username
	local userId = game.Players:GetUserIdFromNameAsync(username)

		if userId then
			local appearance = game.Players:GetHumanoidDescriptionFromUserId(userId)
			print('Attempting to load animation on rig for user '..username)
			applyDescRemote:FireServer(appearance)
			
			if humanoid then
				-- Assuming the animation is stored in the Animations folder
				local animation = animationsFolder:FindFirstChild('Boogie Down') -- replace 'AnimationName' with the name of your animation
				if animation then
					local animationTrack = humanoid:LoadAnimation(animation)
					animationTrack.Looped = false -- Make sure the animation does not loop
					animationTrack:Play()
				else
					print('Animation not found')
				end
			else
				print('Humanoid not found in the character')
			end
		else
			print('User not found')
		end

end)

Normal script in ServerScriptService:

game.ReplicatedStorage.Events.applyDescRemote.OnServerEvent:Connect(function(appearance)
	if typeof(appearance) == "Instance" and appearance:IsA("HumanoidDescription") then
		local dummy = game.Workspace.R6
		local humanoid = dummy.Humanoid
		humanoid:ApplyDescription(appearance)
	else
		warn("Invalid argument: expected 'HumanoidDescription', got " .. typeof(appearance))
	end
end)

The first value returned by OnServerEvent is the player who called :FireServer() on the RemoteEvent; this means that appearance is currently referring to the Player object and not the HumanoidDescription that was sent through.

You should be able to resolve that by making the second parameter reference the data sent through to the server:

Example Revision

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local applyDescRemote = Events.applyDescRemote

applyDescRemote.OnServerEvent:Connect(function(player, appearance)
	if typeof(appearance) == "Instance" and appearance:IsA("HumanoidDescription") then
        -- Continue

This seems to work with no errors however the HumanoidDescription still does not load onto the rig.

Edited server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local applyDescRemote = Events.applyDescRemote

applyDescRemote.OnServerEvent:Connect(function(player, appearance)
	if typeof(appearance) == "Instance" and appearance:IsA("HumanoidDescription") then
		local dummy = game.Workspace.R6
		local humanoid = dummy.Humanoid
		humanoid:ApplyDescription(appearance)
	end
end)

Hmmm, I’m not seeing anything else in either of the scripts that could still be causing it to not work as intended. I’d recommend adding a print statement into the function on the server side right after the HumanoidDescription is applied to make sure it’s really reaching that part of the function.

I tried replicating the general set up and it successfully applied a HumanoidDescription to both R6 and R15 characters models every time, so long as the Players:GetUserIdFromNameAsync() call succeeded.