So I have this “code” here and its sloppy and doesnt work, how would I go about making this look nice and work?
game.Players.PlayerAdded:Connect(function(player) player.CharacterAppearanceLoaded:Connect(function(character) if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 1 then -- Afro wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:FindFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:FindFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(-0,-0,-1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script:WaitForChild("AfroMesh"):Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, -0.20, 0) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 2 then -- Box wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(-0,-0,-1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.BoxMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, 0.15, -0.01) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 3 then -- Business wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(2, 0.8, 2) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.BusinessMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, 0.15, -0.02) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 4 then -- Curly wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(1, 1, 1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.CurlyMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0.03, 0.1, 0) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 5 then -- Dread wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(2,2,2) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.DreadMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, 0.1, -0) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 6 then -- Emo wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(2,2,2) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.EmoMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0.1, 0.3, -0.1) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 7 then -- Faux" wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(-0,-0,-1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.FauxMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0,0.05,0.06) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 8 then -- Longdread wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(1,1,1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.TreckyMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, 0.2, 0) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 10 then -- Longdread wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.BrickColor = BrickColor.new("Really black") p.formFactor = 0 p.Size = Vector3.new(2,2,2) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.LongdreadMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, 0.2, 0) wait(.1) else if player:WaitForChild("leaderstats"):WaitForChild("Hats").Value == 9 then -- Longdread wait(1) local d = character:GetChildren() for i=1, #d do if (d[i].className == "Accessory") then d[i]:remove() end end if character:findFirstChild("Humanoid") ~= nil then -- Accessory script local h = Instance.new("Accessory") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = character:findFirstChild("Head").Position p.Name = "Handle" p.Material = Enum.Material.SmoothPlastic p.formFactor = 0 p.Size = Vector3.new(-0,-0,-1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.AfroMesh:Clone().Parent = p h.Parent = character print("It should work") h.AttachmentPos = Vector3.new(0, -0.20, 0) wait(.1) end end end end end end end end end end end end end end end end end end end end end) end)