How could I make this shorter?

So I have this code that basically makes the owner’s (me) skin completely black and enables particle emitters inside if the parts. I know about one thing (I can’t remember the name, maybe arrays) but I don’t know how to do those yet. This is the current working code I have so far:

game.Players.PlayerAdded:Connect(function(player)
	wait(0.5)
	local char = player.Character
	local p1 = char.UpperTorso
	local p2 = char.Head
	local p3 = char.LeftFoot
	local p4 = char.LeftHand
	local p5 = char.LeftLowerArm
	local p6 = char.LeftLowerLeg
	local p7 = char.LeftUpperArm
	local p8 = char.LeftUpperLeg
	local p9 = char.LowerTorso
	local p10 = char.RightFoot
	local p11 = char.RightHand
	local p12 = char.RightLowerArm
	local p13 = char.RightLowerLeg
	local p14 = char.RightUpperArm
	local p15 = char.RightUpperLeg
	if player.UserId == 151214317 then
		print("work")
		p1.par.Enabled = true
		p2.par.Enabled = true
		p3.par.Enabled = true
		p4.par.Enabled = true
		p5.par.Enabled = true
		p6.par.Enabled = true
		p7.par.Enabled = true
		p8.par.Enabled = true
		p9.par.Enabled = true
		p10.par.Enabled = true
		p11.par.Enabled = true
		p12.par.Enabled = true
		p13.par.Enabled = true
		p14.par.Enabled = true
		p15.par.Enabled = true
		
		p1.Material = Enum.Material.Neon
		p2.Material = Enum.Material.Neon
		p3.Material = Enum.Material.Neon
		p4.Material = Enum.Material.Neon
		p5.Material = Enum.Material.Neon
		p6.Material = Enum.Material.Neon
		p7.Material = Enum.Material.Neon
		p8.Material = Enum.Material.Neon
		p9.Material = Enum.Material.Neon
		p10.Material = Enum.Material.Neon
		p11.Material = Enum.Material.Neon
		p12.Material = Enum.Material.Neon
		p13.Material = Enum.Material.Neon
		p14.Material = Enum.Material.Neon
		p15.Material = Enum.Material.Neon
		
		p2.Mesh:Remove()
		
		p1.Color = Color3.new(0, 0, 0)
		p2.Color = Color3.new(0, 0, 0)
		p3.Color = Color3.new(0, 0, 0)
		p4.Color = Color3.new(0, 0, 0)
		p5.Color = Color3.new(0, 0, 0)
		p6.Color = Color3.new(0, 0, 0)
		p7.Color = Color3.new(0, 0, 0) 
		p8.Color = Color3.new(0, 0, 0)
		p9.Color = Color3.new(0, 0, 0)
		p10.Color = Color3.new(0, 0, 0)
		p11.Color = Color3.new(0, 0, 0)
		p12.Color = Color3.new(0, 0, 0)
		p13.Color = Color3.new(0, 0, 0) 
		p14.Color = Color3.new(0, 0, 0)
		p15.Color = Color3.new(0, 0, 0)
	end
end)

this should do it

game.Players.PlayerAdded:connect(function(player)
	if not (player.UserId == 151214317) then return end

	local char = player.Character or player.CharacterAdded:Wait()

	for _, v in pairs(char:GetChildren()) do
		if not v:IsA("BasePart") then continue end
		
		if v:FindFirstChild("par") then v.par.Enabled = true end
		v.Material = Enum.Material.Neon
		v.Color = Color3.new(0, 0, 0)
	end

	local mesh = char.Head:FindFirstChild("Mesh")
	if mesh then mesh:Remove() end
end)

instead of hard referencing I’m iterating all children of the players’ character, skipping the step if the child isn’t a BasePart (meaning it’s a hat, humanoid, etc)

3 Likes

Oh wow it works perfectly, thanks!

1 Like