How can I make this HumanoidDescription code even better?

Hi, I would like comments from others on my code. This is my first post on the DevForum.

What does the code do and what are you not satisfied with?

My code ensures that all of a player’s character meshes will be removed (they are replaced to blocky shapes) every time he/she spawns. I just think my code isn’t perfect.

What potential improvements have you considered?

I haven’t come across a possible improvement yet.

How (specifically) do you want to improve the code?

I want my code to be clear and run in the fastest way possible.

local Players = game:GetService("Players")

function PlayerAdded(Player) --Player joins

	local function CharacterAdded(Character) --Character of the player loads

		local Humanoid = Character.Humanoid

		local HumanoidDescription = Humanoid:GetAppliedDescription() --Current HumanoidDescription used by the Humanoid

		HumanoidDescription.Head = 0

		HumanoidDescription.LeftArm = 0

		HumanoidDescription.LeftLeg = 0

		HumanoidDescription.RightArm = 0

		HumanoidDescription.RightLeg = 0

		HumanoidDescription.Torso = 0

		repeat wait() until Character.Parent == game:GetService("Workspace") --Wait until the character is in the Workspace

		Humanoid:ApplyDescription(HumanoidDescription) --Apply HumanoidDescription       
	end

	Player.CharacterAdded:Connect(CharacterAdded) --Connect the CharacterAdded function
end

Players.PlayerAdded:Connect(PlayerAdded) --Connect the PlayerAdded function

Why don’t you just edit it in the game settings?

File > Game Settings > Avatar

1 Like

I’ve already tried that, the blocky body parts have the ID ‘‘0’’, but you can’t enter a 0 in the game settings at >Avatar.

Ah, alright

This line:

repeat wait() until Character.Parent == game:GetService("Workspace")

is unnecessary because you use the function to change the humanoid appearance on the character added event, and you’re checking if there is a character after that is fired.

Also you should probably use waitforchild here:
image

1 Like
repeat wait() until Character.Parent == game:GetService("Workspace")

Is necessary because you can only apply HumanoidDescription in workspace.

local Humanoid = Character.Humanoid

I’ve gotten no problems so far doing this. For some reason the Humanoid always exists when spawned.

Edit: typo fixed