Why doesnt this function clear the characters appearance sometimes?

This script works 99% of the time, but the 1% is a chance that it doesn’t run the function at all and doesn’t give the player the shirt/pants, and it wont even clear the appearance of the character.

What is wrong with this script?

local admins = {
	[409522146] = "Dracolyx",
}

_G.connectFunctions = {}

game.Players.PlayerAdded:Connect(function(player)
	local Wins = Instance.new("IntValue",player)
	Wins.Name = "Wins"
	local Loss = Instance.new("IntValue",player)
	Loss.Name = "Losses"
	player.Chatted:Connect(function(msg)
		if player.Character and player.Character:FindFirstChild("Ball") == nil then
			if string.lower(msg) == "ball" then
				if admins[player.userId] then
					local Ball = game.ServerStorage.Ball:Clone()
					Ball.Parent = workspace
					Ball.CFrame = player.Character.HumanoidRootPart.CFrame
				end
			elseif string.lower(msg) == "clean" and admins[player.userId] then
				for _,part in pairs(workspace:GetChildren()) do
					if part.Name == "Ball" then
						part:Destroy()
					end
				end
			end
		end
	end)
	player.CharacterAppearanceLoaded:Connect(function(Character)
		player:ClearCharacterAppearance()
		script:WaitForChild("RecordGUI"):Clone().Parent = Character:WaitForChild("HumanoidRootPart")
		local Humanoid = Character:WaitForChild("Humanoid")
		local Default = script.PlayerColor:Clone()
		Default.Parent = Character
		local Shirt = script.DefaultShirt:Clone()
		local Pants = script.DefaultPants:Clone()
		Shirt.Parent = Character
		Pants.Parent = Character
		local Head = Character:WaitForChild("Head")
		local face = Head:FindFirstChild("face") or Head:FindFirstChild("Face")
		if face then face:Destroy() end
		local DefaultFace = script.DefaultFace:Clone()
		DefaultFace.Parent = Head
		Humanoid.Died:Connect(function()
			player:Kick("You exploiting?")
		end)
	end)
end)
1 Like

Are there any errors in output during the 1% chance that it doesn’t run the function? If so, then please add that to your post. If not, then I suggest adding print() statements inside each function at different positions so that you can test to see what is running and what is not.

1 Like

U can’t do that what u gotta do is make sure that the ball is inside the folder then u can paste this code here

And the folder must be in workspace

local fold = workspace.Folder -- your folder

if fold:GetChildren() then
     fold:ClearAllChildren()
end

It fixed my issue when I made a clean script

1 Like

There aren’t any errors at all that’s the problem. I feel like it could be a loading issue, but even so I wouldn’t know how to fix it.

1 Like

In that case, add prints in different places such as

player.CharacterAppearanceLoaded:Connect(function(Character) 
     print("CharacterAppearance has loaded")
end)

so that you can further determine what the issue is.

1 Like

I don’t know if that will fix the issue because the problem is that the CharacterAppearanceLoaded function isn’t running even though it’s in the playeradded function. We already know it doesn’t clear the appearance, and everything else won’t work if the function doesn’t run.

Something is getting in the way of the CharacterAppearanceLoaded function.

It’s also a 1% chance issue so it’s hard to actually test something like this. All I know is that it happened before, and it’s bound to happen again.

1 Like

Yes, but you still need to see if CharacterAppearanceLoaded runs even if the appearance is not cleared.

1 Like

well considering it doesn’t clear the characters appearance I would like to think that means the function doesn’t run.

1 Like