Keep blocky character


#1

Hello , so i’ve been looking for a script thatdestroy the character mesh of a player
when his avatar spawns

i’m currently using this script but it takes a second to destroy the CharacterMesh

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		wait(1)
		local l = c:GetChildren()
		
		for i = 1 , #l do
			local l = l[i]
			if l :IsA("CharacterMesh") then
				l:Destroy()
			end
		end
	end)
end)

is there any other faster ways to do this ?


#2

image


#4
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait()
		for i,v in pairs(char:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Destroy()
			end
		end
	end)
end)

#5

All the meshes may not load in time. That’s the problem here.


#6

Remove the wait(1) statement and before you’ve gone through your loop and destroyed the meshes add a .ChildAdded event to check when a CharacterMesh is added.

Edit:

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char.ChildAdded:Connect(function(ch)
            if ch:IsA("CharacterMesh") then
                ch:Destroy()
            end
        end)
        for _, ch in ipairs(char:GetChildren()) do
            if ch:IsA("CharacterMesh") then
                ch:Destroy()
            end
        end
    end)
end)

#7

Player.CanLoadCharacterApearance = false
This will remove the loading of a player’s appearance, and replace it with a default gray block dude.


#8

True. I think there should be a ChildAdded event

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait()
        Char.ChildAdded:Connect(function(child)
            if child:IsA("CharacterMesh") then
               child:Destroy()
            end
        end)
	end)
end)

#9
local Players = game.Players

function PlayerJoined(Player)
	local function RemoveMeshes(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		wait()
		
		local CurrentDescription = Humanoid:GetAppliedDescription() -- gets the current applied description
		-- changes all of the body parts description to 0 (default)
		CurrentDescription.Head = 0
		CurrentDescription.Torso = 0
		CurrentDescription.LeftArm = 0
		CurrentDescription.RightArm  = 0
		CurrentDescription.LeftLeg = 0
		CurrentDescription.RightLeg = 0
		Humanoid:ApplyDescription(CurrentDescription) -- we only changes the body parts so the rest stays the same
		
	end
	Player.CharacterAdded:Connect(RemoveMeshes)
end

Players.PlayerAdded:Connect(PlayerJoined)

this works instantly when a player joins and when they reset

you could also change the scale with this method too if you wanted

use HumanoidDescriptions


#10

Forgot about humanoidDescriptions, but it has the same effect as removing the characters appearance.


#11

No it does not, removing the appearance removes everything including shirts hats faces etc

the method I used only changes the body parts and nothing else

not loading appearance

image

using humanoid descriptions

image

image


#12

Sorry, I skimmed through your post.


#13

Wow, I never really knew about that method! Thanks for posting it!


#14

Thanks ! didnt know ChildAdded existed.


#15

i’m using R6 so it’s easier , also i fixed the script with child Added , thanks anyways !


#16

Why’re you guys spoon feeding code with no after-explanation as to what was changed or giving him learning resources? There’s no point if OP doesn’t learn.


One thing I’ve noticed, first off: your code block hasn’t been formatted properly. When posting code to the DevForum, put your code between a code block. You can create that by using three back ticks.

```lua
– Your code
```

print("Hello world!")

Next thing I noticed is, well, the code itself. Here are some issues I’ve observed with it:

  • You are using an unnecessary wait statement to reinvent the wheel, where functions are already provided for you. You can change this to use CharacterAppearanceLoaded and wait until the signal is fired, which tells the script that the avatar’s assets have loaded. On the other hand, since this doesn’t fire for blank characters, you can use ChildAdded and destroy CharacterMesh class children when they’re added.
  • You’re using the wrong type of for loop; try using a key-value loop instead of via index (since the index is unimportant) [1]
  • Try indexing your services as a local variable at the top of your script first, via GetService (GetService is a canonical way of fetching services)
  • You can use the HumanoidDescription system to preserve a certain style for the avatar to look, by applying a 0 value for each limb; you can then apply this HumanoidDescription to the character via a script in StarterCharacterScripts

[1]:

for _, object in pairs(Character:GetChildren()) do
    print(object, object.ClassName) -- Replace with your own code
end

#17

image

Make a StarterCharacter if you want to keep the initial player avatar the same when they join…


#18

OP is trying to remove bundles, not overwrite the entire character. StarterCharacter isn’t used for this purpose; it’s for when you want to overall change the way a character appears, functions or even how it’s assembled. HumanoidDescriptions or reformatting the default character if you’re only aiming to purge a certain type of asset are sufficient enough.


#19

i always used :GetChildren() then for i , because i don’t see the difference ?
can you explain me ?


#20

The process is still fairly the same but the methodology behind it is different. I don’t use the index part or re-enter the model hierarchy via index since knowing a numerical order is not necessary - you’ll notice right below your for entry statement that you still need to index a child local l = l[i]. This could also be problematic if the array shifts down (which iirc it does, but I can’t remember).

I opted to use a key-value statement for my loop, ditching index, because of the very fact that knowing index is not necessary. It simply runs a scope per child of the ancestor. It’s easier on the eyes, doesn’t require unnecessary overhead (by a few ms anyway) or run into any potential trouble.