CharacterMesh doesn't delete!

Hello! I’ve a delete charactermesh script that should delete the meshes however, it doesn’t. This breaks my game because ragdoll doesn’t work as intended with this. Also it doesn’t print.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(char)
		for i, mesh in pairs(char:GetChildren()) do
			if mesh:IsA("CharacterMesh") then
				mesh:Destroy()
				print("Destroyed")
			end
			
		end
		
	end)
	
end)

Im not a scripter, but this might help:

  1. The CharacterAppearanceLoaded event might not be the best choice. It’s not always guaranteed that CharacterMesh objects will be loaded at this point. Instead, maybeuse the CharacterAdded event to ensure that you catch the character when it’s fully loaded?

  2. Checking if char is valid. Before iterating through the children of char , you should check if char is not nil, as it’s possible that the character isn’t loaded yet if you use ‘CharacterAppearanceLoaded’

Maybe this could work (I could be wrong):

local Players = game:GetService("Players")

local function removeCharacterMeshes(char)
    if not char then
        return
    end

    for _, mesh in pairs(char:GetChildren()) do
        if mesh:IsA("CharacterMesh") then
            mesh:Destroy()
            print("Destroyed")
        end
    end
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        removeCharacterMeshes(character)
    end)
end)

^ I connected the PlayerAdded event to create a connection for each player when they join the game. When a player’s character is fully loaded, the CharacterAdded event is triggered, and we call the removeCharacterMeshes function to delete any CharacterMesh objec.The function also checks if the character is valid before attempting to remove meshes.

2 Likes

I’m not too sure, but are CharacterMeshes in the player in the Player folder?
Test and look at your player in the workspace compared to your player in the Players folder.

It loads the characteradded() however, doesn’t print “Destroyed”

No, I only see accessories. I want to delete the roblox bundles because it messes up my game

Where do you expect it to print? Can I see snapshots to further help you?

Accessories in which player?
What if you delete the meshes in the local player?

local Players = game:GetService("Players")

local function removeCharacterMeshes(char)
	if not char then
		print("No char?") -- Doesn't print
		return
	end

	for _, mesh in pairs(char:GetChildren()) do
		if mesh:IsA("CharacterMesh") then
			mesh:Destroy()
			print("Destroyed") -- Doesn't print
		end
	end
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		print("ADDED") -- prints
		removeCharacterMeshes(character)
	end)
end)

Most of them don’t print.

Like normal accessories such hair, hats, glasses, however, I don’t see their bundles/character meshes. Mayble, I’ll delete it in local

The message No char will only print if the char variable is nil. If it’s not printing, this means that the char variable within removeCharacterMeshes functionis not nil, and so the condition for printing “No char” is never met. Is char nil?

The message “Destroyed” will only print if a CharacterMesh is found and destroyed within the loop. If it’s not printing, it means that the loop isn’t finding any CharacterMesh objects within the char object you’re passing to removeCharacterMeshes. Double-check if your characters actually contain CharacterMesh ojects. If they don’t, that would explain why “Destroyed” isn’t printing.

Idk if this is what your asking
Happy to help :smiley:

1 Like

This is what I’m looking for! I’ve probably worded it wrongly but after modifying it, it works like a charm! Thanks

1 Like

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