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)
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?
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.
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.
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)
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.