Avatar Generation Problem

  1. What do I want to achieve?

I’m trying to make a default skin generator removing the accessories of the player and making its torso a random color. (the legs get black and the arms and head yellow but that’s irrelevant)

When a player joins it will repeat a pcall : if the pcall is not successful then it will add 1 attempt. It will repeat until there are 5 attempts.

  1. What is the issue?

Whatever I try the attempt remains at 1 so it keeps regenerating the avatar and it looks like you gonna have a seizure if you look at the torso.

  1. What solutions have I tried so far?

Tried everything. Repeating until attempt == 5 or success ? Doesn’t generate the avatar. Make so that if the pcall has succeeded, you break the loop ? Doesn’t generate the avatar. Forcing the way that if it is successful the attempt directly gets to 5 ? Still doesn’t generate the avatar.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	
	local attempt = 1
	
	local success = nil
	local failure = nil
	
	char.Humanoid.Health = math.huge

	repeat
		local success, failure = pcall(function()

			for i, v in pairs(char:GetDescendants()) do
				if v:IsA("Accessory") or v:IsA("Shirt") or v:IsA("Pants") or v:IsA("ShirtGraphic") then
					v:Destroy()
				elseif v:IsA("BodyColors") then
					v.HeadColor = BrickColor.Yellow()
					v.LeftArmColor = BrickColor.Yellow()
					v.RightArmColor = BrickColor.Yellow()
					v.LeftLegColor = BrickColor.Black()
					v.RightLegColor = BrickColor.Black()

					v.TorsoColor3 = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
				end
			end

		end)


		if not success then
			warn("Avatar generation failure")
			attempt += 1
		end
		
		wait()
	until attempt == 5
	
	if not success then
		player:Kick("Avatar generation failed due to " .. failure .. ".")
	end
end)

Vid of the bug :

PLZ HELP

can’t you just:

players.PlayerAdded:Connect(function(player)
 player.CharacterAdded:Connect(function(char)--otherwise it only runs once
  local desc = Instance.new("HumanoidDescription")
  desc.HeadColor = BrickColor.Yellow()
  desc.LeftArmColor = BrickColor.Yellow()
  desc.LeftLegColor = BrickColor.Black()
  desc.RightArmColor = BrickColor.Yellow()
  desc.RightLegColor = BrickColor.Black()
  desc.TorsoColor = Color3.fromRGB(math.random(255), math.random(255), math.random(255))

  char.Humanoid:LoadCharacterWithHumanoidDescription(desc)
 end)
end)

this will work, and pcall isn’t needed because there can be no errors, since nothing could possibly be nil, if you are unsure you can always wrap this in a pcall but it really isn’t needed.

Hope this helps!

edit:
the reason why your previous code failed is because it was only incrementing attempt when the attempt failed, but when it succeeded it didn’t increment it and just kept going, so since your code never errors it would always keep going again and again, so to fix that you should’ve added in the if statement:

	if not success then
		warn("Avatar generation failure")
		attempt += 1
        else 
                break--stop the loop
	end

an alternate way would be:

repeat 
--...
until attempt > 5 or success --until attempt is greater than 5 or success is true.

Kinda right, thing i already tried second solution but don’t work : it loads my avatar instead of the avatar intended. But the first solution seems cool, just need to put color3 instead of brick color.

Ima try.

oh my bad, I was not thinking when I wrote that script, yea brickcolor and color3 are not the same uhh, but I was on autopilot sorry haha.

well the second solution was just an extension to your first script with the only changes being the if statement with the warn call or the until header, also the reason why the until header might not work is because you are redefining success in the loop by doing local success, failure so your enclosing success variable doesn’t get updated which is the variable that the header uses, but that’s just my theory on why the second one might not work.

I improved your script a bit but still it don’t work : its just loads my roblox avatar and not the intended avatar.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)--otherwise it only runs once
		for i, v in pairs(char:GetDescendants()) do
			if v:IsA("Accessory") or v:IsA("Shirt") or v:IsA("ShirtGraphic") then	-- DESTROYS UNNECESSARY ACCESSORIES
				v:Destroy()
			end
		end
		
		local desc = Instance.new("HumanoidDescription")

		desc.HeadColor = Color3.fromRGB(255, 255, 0)
		desc.LeftArmColor = Color3.fromRGB(255, 255, 0)
		desc.LeftLegColor = Color3.fromRGB(0, 0, 0)
		desc.RightArmColor = Color3.fromRGB(255, 255, 0)
		desc.RightLegColor = Color3.fromRGB(0, 0, 0)
		desc.TorsoColor = Color3.fromRGB(math.random(255), math.random(255), math.random(255))

		char.Humanoid:LoadCharacterWithHumanoidDescription(desc)
	end)
end)

HELPPP IT DOESNT GENERATE THE AVATAR IT SAYS LoadCharacterWithHumanoidDescription is not a valid member of Humanoid “Workspace.fancym0000.Humanoid”

P-S : The script is in serverscriptservice, don’t know if it can help but felt like it needed more context.

omg I’m such a dumbass, woops I was high or something idk.
The reason why it dosn’t work is because the loadcharwithumdesc() is part of the player object not the humanoid.

I literally just looked at th documentation because I knw this function exists.
so it is:

player:LoadCharacterWithHumanoidDescription(desc)

also you don’t need to destroy accessories because they are unloaded when a new desc is used instead.

edit: here
Player | Documentation - Roblox Creator Hub

edit: my E key is broken, it dosn’t type E half of the time…

ye ye don’t worry i already fixed it. Also I forgor to put the location of the desc to player.
THANKS FOR YOUR SERVICE

local players = game:GetService("Players")


players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		for i, v in pairs(char:GetDescendants()) do
			if v:IsA("Accessory") or v:IsA("Shirt") or v:IsA("ShirtGraphic") then
				v:Destroy()
			end
		end
		
		local desc = Instance.new("HumanoidDescription", player)

		desc.HeadColor = Color3.fromRGB(255, 255, 0)
		desc.LeftArmColor = Color3.fromRGB(255, 255, 0)
		desc.LeftLegColor = Color3.fromRGB(0, 0, 0)
		desc.RightArmColor = Color3.fromRGB(255, 255, 0)
		desc.RightLegColor = Color3.fromRGB(0, 0, 0)
		desc.TorsoColor = Color3.fromRGB(math.random(255), math.random(255), math.random(255))

		player:LoadCharacterWithHumanoidDescription(desc)
	end)
end)

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