How can I replace the old head with the new Dynamic Head?

Roblox have just released a new feature called “Dynamic Head” and I really wanted to try it on my game, I already have the Dynamic Head model but I don’t know how to replace it properly. When I replace it by cloning and destroying the old head, the new head is bigger and unproportional. It would be awesome if somebody could tell me the correct way of doing it, thank you!

I haven’t looked into it yet, but you’ll probably have to create a custom character.

https://education.roblox.com/en-us/resources/education/arcade/customCharacter

2 Likes

Hello,
if you just want the player’s avatar to be swapped completely to a full dynamic head avatar (so the full body), then you can just download the dynamic head example avatar and rename it to StarterCharacter and put it into the StarterPlayer folder. Then on running the game the player’s avatar would be that dynamic head avatar.

If you instead want to let the player keep his/her avatar’s body and only swap the head to a dynamic head, here’s an example place showing how you could achieve that:

Dynamic-Head-SwapPlayerHeadToDynamicHead.rbxl (269.0 KB)

In this place you can see in StarterPlayer/StarterPlayerScripts there is a LocalScript called TriggerSwapHead. In that it will trigger calling a function on the server for the local player via a remote event.

local replicatedStorage = game:GetService('ReplicatedStorage')
local players = game:GetService('Players')
local avatarRemoteEvent = replicatedStorage:WaitForChild('AvatarRemoteEvent')

local Players = game:GetService("Players")

local function playerAdded(player)
	print("playerAdded")
	local localPlayer = players.LocalPlayer
	if player == localPlayer then
		local character = player.Character or player.CharacterAdded:Wait()
		avatarRemoteEvent:FireServer("swapHead", character)	
	end
end

-- get existing players
for _, player in pairs(Players:GetPlayers()) do 
	playerAdded(player)
end
-- listen for new players
Players.PlayerAdded:Connect(playerAdded)

The related Server Script is ServerScriptService/SwapHeadOnServer
In that script when the event to swap the head comes in, it will swap the head of the player’s character to the dynamic head of the avatar character in ServerStorage/DynamicHeadAvatars/DynamicHeadBlockyMale
(
Regarding the HeadScale
see the SwapHead function where i destroy current HeadScale NumberValue property in the humanoid of the player avatar and add the one from the other avatar in to use the scale of that one.
(Could be simplified further, was just a quick test implementation to get you started)
)

function SwapHead(player)
	local currentCharacter = player.Character
	local newCharacter = dynamicHeadBlockyMaleAvatar
	print("SwapHead() : Swapping Head to head of " .. newCharacter.Name)	

	local toCloneHead = newCharacter:WaitForChild("Head")

	local humanoid = currentCharacter:FindFirstChildOfClass("Humanoid")

	local toCloneBodyHumanoid = newCharacter:WaitForChild("Humanoid")

	--avoid avatar dying sometimes in swap head moment:
	humanoid.RequiresNeck = false

	for _, part in ipairs(humanoid:GetDescendants()) do
		if part:IsA("NumberValue") and part.Name == "HeadScale" then
			part:Destroy()
		end
	end	

	for _, part in ipairs(toCloneBodyHumanoid:GetDescendants()) do
		local clonedProp = part:Clone()
		if clonedProp:IsA("NumberValue") and part.Name == "HeadScale"  then
			clonedProp.Parent = humanoid
		end
	end			

	local clonedHead = toCloneHead:Clone()
	humanoid:ReplaceBodyPartR15(Enum.BodyPartR15.Head, clonedHead)

	humanoid:buildRigFromAttachments()
	humanoid.RequiresNeck = true
end

Hope it helps =)

4 Likes