Help Serializing a Humanoid Description

Hello, im trying to serialize a humanoid description in a table to save it into a datastore but for some reason when i try to apply the deserialized humanoid description into a rig i get this error:


Here is my code (Is a Module Script)

-- Module made to Serialize and UnSerialize objects into tables
-- @sixgera

local Serialization = {}
function Serialization.serializeHumanoidDescription(Description:HumanoidDescription)
	local Result = {
		Propierties = {
			Shirt = Description.Shirt,
			Pants = Description.Pants,
			Face = Description.Head,
			Torso = Description.Torso,
			RightLeg = Description.RightLeg,
			LeftLeg = Description.LeftLeg,
			LeftArm = Description.LeftArm,
			RightArm = Description.RightArm,
			Head = Description.Head,
			GraphicTShirt = Description.GraphicTShirt,
			BodyTypeScale = Description.BodyTypeScale,
			DepthScale = Description.DepthScale,
			HeadScale = Description.HeadScale,
			HeightScale = Description.HeightScale,
			ProportionScale = Description.ProportionScale,
			WidthScale = Description.WidthScale,
			BackAccessory = Description.BackAccessory,
			FaceAccessory = Description.FaceAccessory,
			FrontAccessory = Description.FrontAccessory,
			HairAccessory = Description.HairAccessory,
			HatAccessory = Description.HatAccessory,
			NeckAccessory = Description.NeckAccessory,
			ShouldersAccessory = Description.ShouldersAccessory,
			WaistAccessory = Description.WaistAccessory,
			-- ANIMATIONS --
			ClimbAnimation = Description.ClimbAnimation,
			FallAnimation = Description.FallAnimation,
			IdleAnimation = Description.IdleAnimation,
			JumpAnimation = Description.JumpAnimation,
			MoodAnimation = Description.MoodAnimation,
			RunAnimation = Description.RunAnimation,
			SwimAnimation = Description.SwimAnimation,
			WalkAnimation = Description.WalkAnimation,
		},
		Colors = {
			HeadColor = {Description.HeadColor.R,Description.HeadColor.G,Description.HeadColor.B},
			LeftArmColor = {Description.LeftArmColor.R,Description.LeftArmColor.G,Description.LeftArmColor.B},
			RightArmColor = {Description.RightArmColor.R,Description.RightArmColor.G,Description.RightArmColor.B},
			LeftLegColor = {Description.LeftLegColor.R,Description.LeftLegColor.G,Description.LeftLegColor.B},
			RightLegColor = {Description.RightLegColor.R,Description.RightLegColor.G,Description.RightLegColor.B},
			TorsoColor = {Description.TorsoColor.R,Description.TorsoColor.G,Description.TorsoColor.B},
		}
	}
	return Result
end
function Serialization.deSerializeHumanoidDescription(Serialized)
	local HumanoidDescription = Instance.new("HumanoidDescription")
	-- First Propierties --
	for i,v in pairs(Serialized.Propierties) do
		if v ~= 0 then
			HumanoidDescription[i] = v
		end
	end
	-- Then Colors --
	for p,c in pairs(Serialized.Colors) do
		HumanoidDescription[p] = Color3.fromRGB(c[1],c[2],c[3])
	end
	return HumanoidDescription
end
return Serialization
1 Like

Also i want to add that i get that error when i apply the description into a humanoid

1 Like

You’re deserializing the color wrong. Color3.fromRGB needs values between 0 - 255, but you’re saving the colors as a value between 0 - 1. You also misspelt properties. Pairs/ipairs is not needed either, because Roblox added generalized iteration which performs faster.

Code:

-- Module made to Serialize and UnSerialize objects into tables
-- @sixgera

local Serialization = {}
function Serialization.serializeHumanoidDescription(Description:HumanoidDescription)
	local Result = {
		Properties = {
			Shirt = Description.Shirt,
			Pants = Description.Pants,
			Face = Description.Head,
			Torso = Description.Torso,
			RightLeg = Description.RightLeg,
			LeftLeg = Description.LeftLeg,
			LeftArm = Description.LeftArm,
			RightArm = Description.RightArm,
			Head = Description.Head,
			GraphicTShirt = Description.GraphicTShirt,
			BodyTypeScale = Description.BodyTypeScale,
			DepthScale = Description.DepthScale,
			HeadScale = Description.HeadScale,
			HeightScale = Description.HeightScale,
			ProportionScale = Description.ProportionScale,
			WidthScale = Description.WidthScale,
			BackAccessory = Description.BackAccessory,
			FaceAccessory = Description.FaceAccessory,
			FrontAccessory = Description.FrontAccessory,
			HairAccessory = Description.HairAccessory,
			HatAccessory = Description.HatAccessory,
			NeckAccessory = Description.NeckAccessory,
			ShouldersAccessory = Description.ShouldersAccessory,
			WaistAccessory = Description.WaistAccessory,
			-- ANIMATIONS --
			ClimbAnimation = Description.ClimbAnimation,
			FallAnimation = Description.FallAnimation,
			IdleAnimation = Description.IdleAnimation,
			JumpAnimation = Description.JumpAnimation,
			MoodAnimation = Description.MoodAnimation,
			RunAnimation = Description.RunAnimation,
			SwimAnimation = Description.SwimAnimation,
			WalkAnimation = Description.WalkAnimation,
		},
		Colors = {
			HeadColor = {Description.HeadColor.R,Description.HeadColor.G,Description.HeadColor.B},
			LeftArmColor = {Description.LeftArmColor.R,Description.LeftArmColor.G,Description.LeftArmColor.B},
			RightArmColor = {Description.RightArmColor.R,Description.RightArmColor.G,Description.RightArmColor.B},
			LeftLegColor = {Description.LeftLegColor.R,Description.LeftLegColor.G,Description.LeftLegColor.B},
			RightLegColor = {Description.RightLegColor.R,Description.RightLegColor.G,Description.RightLegColor.B},
			TorsoColor = {Description.TorsoColor.R,Description.TorsoColor.G,Description.TorsoColor.B},
		}
	}
	return Result
end
function Serialization.deSerializeHumanoidDescription(Serialized)
	local HumanoidDescription = Instance.new("HumanoidDescription")
	-- First Properties --
	for i,v in Serialized.Properties do
		if v ~= 0 then
			HumanoidDescription[i] = v
		end
	end
	-- Then Colors --
	for p,c in Serialized.Colors do
		HumanoidDescription[p] = Color3.new(c[1],c[2],c[3])
	end
	return HumanoidDescription
end
return Serialization

Your code worked fine other than the color glitch though, which is why I ask, are you sure the HumanoidDescription you’re serializing is actually valid?

image

1 Like

are you trying the code in a server side or client script? , because im trying it on a client script

local Serialize = require(game.ReplicatedStorage.Resources.GeraModules.Serialization)

script.Parent.TextButton.MouseButton1Click:Connect(function()
	
	local infoTbl = Serialize.serializeHumanoidDescription(game.Players.LocalPlayer.Character.Humanoid.HumanoidDescription)
	print(infoTbl)
	local Rig = game.ReplicatedStorage.Resources.Rig:Clone() -- Empty Character
	Rig.Parent = workspace
	Rig:PivotTo(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame)
	
	local Description = Serialize.deSerializeHumanoidDescription(infoTbl)
	
	Description.Parent = Rig
	
	Rig.Humanoid:ApplyDescription(Description)
	

end)

:ApplyDescription only works on the server. You should also be using Humanoid:GetAppliedDescription() instead of Humanoid.HumanoidDescription.

1 Like

The Apply Description works in the client too if the character is owned or cloned by the client , but also im using the GetAppliedDescription() function on the Description and im getting the same error , i think this is a error of roblox or something because i corrected the code with the stuff that you said but it has the same error:

local Serialize = require(game.ReplicatedStorage.Resources.GeraModules.Serialization)
-- Serialization Testing ONLY
script.Parent.TextButton.MouseButton1Click:Connect(function()
	local Humanoid:Humanoid = game.Players.LocalPlayer.Character.Humanoid
	local infoTbl = Serialize.serializeHumanoidDescription(Humanoid:GetAppliedDescription())
	print(infoTbl)
	-- Rig Owned by client thats why apply description works in client here
	local Rig = game.ReplicatedStorage.Resources.Rig:Clone() -- Empty Character
	Rig.Parent = workspace
	Rig:PivotTo(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame)
	
	local Description:HumanoidDescription = Serialize.deSerializeHumanoidDescription(infoTbl)
	
	Description.Parent = Rig
	
	Rig.Humanoid:ApplyDescription(Description)
	
end) 

Get rid of the Description.Parent = rig. You don’t need to set the parent before applying the description.

Also my apologies, you were right: Make Humanoid:ApplyDescription() available on the client - #10 by Wonuf

1 Like

Even with that doesnt work for me :sob:, im thinking that prolly is a roblox bug or something in the Apply Description method idk

Works fine for me:

I’ll try using your avatar and testing.

1 Like

Ohhhhhhhh, I found the problem. For some reason, you set Face to Description.Head, which messed up the serialization.
image

Code:

-- Module made to Serialize and UnSerialize objects into tables
-- @sixgera

local Serialization = {}
function Serialization.serializeHumanoidDescription(Description:HumanoidDescription)
	local Result = {
		Properties = {
			Shirt = Description.Shirt,
			Pants = Description.Pants,
			Face = Description.Face,
			Torso = Description.Torso,
			RightLeg = Description.RightLeg,
			LeftLeg = Description.LeftLeg,
			LeftArm = Description.LeftArm,
			RightArm = Description.RightArm,
			Head = Description.Head,
			GraphicTShirt = Description.GraphicTShirt,
			BodyTypeScale = Description.BodyTypeScale,
			DepthScale = Description.DepthScale,
			HeadScale = Description.HeadScale,
			HeightScale = Description.HeightScale,
			ProportionScale = Description.ProportionScale,
			WidthScale = Description.WidthScale,
			BackAccessory = Description.BackAccessory,
			FaceAccessory = Description.FaceAccessory,
			FrontAccessory = Description.FrontAccessory,
			HairAccessory = Description.HairAccessory,
			HatAccessory = Description.HatAccessory,
			NeckAccessory = Description.NeckAccessory,
			ShouldersAccessory = Description.ShouldersAccessory,
			WaistAccessory = Description.WaistAccessory,
			-- ANIMATIONS --
			ClimbAnimation = Description.ClimbAnimation,
			FallAnimation = Description.FallAnimation,
			IdleAnimation = Description.IdleAnimation,
			JumpAnimation = Description.JumpAnimation,
			MoodAnimation = Description.MoodAnimation,
			RunAnimation = Description.RunAnimation,
			SwimAnimation = Description.SwimAnimation,
			WalkAnimation = Description.WalkAnimation,
		},
		Colors = {
			HeadColor = {Description.HeadColor.R,Description.HeadColor.G,Description.HeadColor.B},
			LeftArmColor = {Description.LeftArmColor.R,Description.LeftArmColor.G,Description.LeftArmColor.B},
			RightArmColor = {Description.RightArmColor.R,Description.RightArmColor.G,Description.RightArmColor.B},
			LeftLegColor = {Description.LeftLegColor.R,Description.LeftLegColor.G,Description.LeftLegColor.B},
			RightLegColor = {Description.RightLegColor.R,Description.RightLegColor.G,Description.RightLegColor.B},
			TorsoColor = {Description.TorsoColor.R,Description.TorsoColor.G,Description.TorsoColor.B},
		}
	}
	
	return Result
end
function Serialization.deSerializeHumanoidDescription(Serialized)
	local HumanoidDescription = Instance.new("HumanoidDescription")
	-- First Properties --
	for i,v in Serialized.Properties do
		if v ~= 0 then
			HumanoidDescription[i] = v
		end
	end
	-- Then Colors --
	for p,c in Serialized.Colors do
		HumanoidDescription[p] = Color3.new(c[1],c[2],c[3])
	end
	return HumanoidDescription
end
return Serialization
2 Likes

Ohh i didnt notice that thanks a lot for your help!

1 Like

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