Trying to change the head of the player but without success

So that’s shorter one but basically I’m trying to change the heads mesh ids of every player because it’s needed for my game. So if I try to do it manually it works:

image


but I can’t find how to script it. Here is the script and my best try to do it:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		local Childrens = character:GetChildren()

		for i, child in pairs(Childrens) do
			if child.ClassName == "Accessory" and child.Name ~= "SpawnLocation" and child.AccessoryType == Enum.AccessoryType.Hat then
				child:Destroy()
			end
		end
		local Head = character:FindFirstChild("Head")
		Head.MeshId = 5591363797
	end)
end)

Obviously I did something wrong but I have no Idea. The log is this: The current thread cannot write 'MeshId' (lacking capability NotAccessible) - Server - RemoveHats:11

I can give you more information about anything you need to know, thanks for the helping!

Mesh IDs can’t be changed during run time, hence the error.

Assuming you want to always have the player’s head changed (which I believe is the case based on the code), you should instead change the following setting in Game Settings

2 Likes

Wouldn’t this require uploading the head to catalogue, which costs 750 Robux?

Ah, good point.
In that case, you’ll need to have the mesh saved somewhere, then clone it over to the character, set up any connections the original head had, then delete the original head.

1 Like

maybe some sort of function that does this could work?

I am not good at scripting but; Maybe you could take this and make a working function?

local player = game:GetService(“Players”)
local customHead = game.Workspace[“Custom Head”].customHead
local headReplaceFunction = function(headReplaceFunction)
wait(0)
customHead:Clone()
local headClone = customHead:Clone()
headClone.Anchored = false
headClone.CanCollide = false
headClone.Cframe = player.Head.Cframe
local constraint = Instance.new(“WeldConstraint”)
constraint.Enabled = true
constraint.Part0 = script.Parent
constraint.Part1 = customHead
constraint.Parent = headClone
you can probably tell I just started learning luau lol

That worked for me because I wanted every player to have the same head to be fair(part of the gameplay). So basically the heads uploaded by roblox are public to everyone so I used one of them instead.: Chiseled - Roblox
Thanks a lot!

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