Issues with modifying a character

Hey developers, I am currently developing a game in which I need to “reset” a players character back to a base character: default meshes and shirts.
Here’s my code:
Please note that script.Dummy is equal to a starter character

				for _, Child in pairs(Character:GetChildren()) do
					if Child:IsA("Accessory") or Child:IsA("Shirt") or Child:IsA("Pants") then
					elseif Child:IsA("MeshPart") then
						Child.MeshId = script.Dummy[Child.Name].MeshId -- Error
					elseif Child:IsA("Part") and Child:FindFirstChildOfClass("SpecialMesh") then
						Child:FindFirstChildOfClass("SpecialMesh").MeshId = ""
						if Child.Name == "Head" and not Child:FindFirstChild("Face") then
							local fc = script.Dummy.Head.face:Clone()
							fc.Parent = Child

On the line

Child.MeshId = script.Dummy[Child.Name].MeshId

I am getting the error Unable to assign property MeshId. Script write access is restricted.

Does anyone have a fix for this? Or another way of writing this code?

1 Like

I don’t know what modifications (exactly what do u mean by default, your custom default, or the player’s normal avatar?) you’re doing to the player model, but I would suggest just reloading the player’s character.

-- Player
local pos = player.Character.HumanoidRoot.Part.CFrame
player.Character.HumanoidRootPart.CFrame = pos

Also, Roblox apparently doesn’t allow editing meshes of a player (from what I could find).
I would first try without the repositioning, but I think they’ll get sent back to the spawn.

You can’t modify Meshpart MeshIds at runtime. Consider using HumanoidDescription

local DummyAppearance ="HumanoidDescription")
-- modify as you wish


Looked through the devforum, recommend checking this out. Is there a way to get around Script write access is restricted in studio?

You can only modify SpecialMeshes whilst the game is running.

Like I said in OP, I am pretty much just resetting a player’s character to that of a reference character: something you maybe could have inferred looking at the code? In my situation, using Player:LoadCharacter() doesn’t really work because I am using the player’s normal avatar and just removing any special meshes, e.g korblox or headless etc. Essentially just getting everything back to one default while maintaining certain elements such as skin tone and face.

I did try to use this, but as I am loading a lot of assets into the game at one time, using HumanoidDescriptions took too long to load the character.

Can you define what you mean by “whist the game is running”? Because this script runs while the game is active and players are playing: is there a difference between that and the game “running”?

I’ve done some more research into this, and it looks like scripts cant modify meshids flatout: does anyone have another solution for this? Bit stuck here.