Problem with changing character meshes

For a game I’m trying to make, i need to know how to:

  1. Search the player’s model in the Workspace
  2. Find anything with the class name “CharacterMesh”
  3. Delete it from the player’s model so the player looks blocky.

Code:

function changePlayerBodyType(player)
	local player2 = workspace:FindFirstChild(player.Name)
	if player2:FindFirstChild("CharacterMesh") then
		for i,v in pairs(player2:GetChildren("CharacterMesh")) do
			v:Destroy()
		end
	end
end

game.Players.PlayerAdded:Connect(changePlayerBodyType)

you can try using the Humanoid Description System instead, just create a humanoid description with the properties you need and apply that to the players.

Does 0 stand for the blocky parts?

I’m not entirely sure why you added a string on the parameters of :GetChildren("CharacterMesh"), :GetChildren() only returns the array of the instance’s children that its function is connected to and has no parameters available.

I would do it like this:


function changePlayerBodyType(player)

for i, v in pairs(player.Character:GetChildren()) do

if v:IsA("CharacterMesh") then -- checks if its a character mesh type
         
         v:Destroy() -- destroys it if it is

           end
     end
 end

game.Players.PlayerAdded(changePlayerBodyType)

I apologize if the indentation isn’t good enough since I am typing this on mobile.

Yes it does. I’d experiment with humanoid descriptions, as they are extremely helpful.

its fine ill try that out anyways

The way you typed it out didn’t work, but I modified the text and it worked. Thanks anyway :slight_smile:
What I used:

function changePlayerBodyType(player)
	local player2 = workspace:WaitForChild(player.Name)
	for i,v in pairs(player2:GetChildren()) do
		if v:IsA("CharacterMesh") then
			v:Destroy()
		end
	end
end

game.Players.PlayerAdded:Connect(changePlayerBodyType)
1 Like

It probably couldn’t find the character but either way I was typing this on mobile and didn’t check whether it would work in studio. I’m glad I’ve helped you regardless!

I posted a script in a different post that removes the player’s bundles.

1 Like