Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Im making a Customization with roblox hairs and everytime I switch hairs its breaks, Help?

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	print('working')
	local hairs = player:WaitForChild('Customization'):FindFirstChild('Hair')
	local hair = hairs.Hair1:Clone()
	local hair2 = hairs.Hair2:Clone()
	local hair3 = hairs.Hair3:Clone()
	local hair4 = hairs.Hair4:Clone()
	local hair5 = hairs.Hair5:Clone()
	local hair6 = hairs.Hair6:Clone()
	local hair7 = hairs.Hair2:Clone()
	local character = player.Character
	if player.Character:FindFirstChildWhichIsA('Accessory') ~= nil then
		player.Character:FindFirstChildWhichIsA('Accessory'):Destroy()
		

		hair.Parent = character
	end
	if character:FindFirstChild('Hair1') == nil then
		hair.Parent = character
	end
	if character:FindFirstChild('Hair2') == nil then
		character:FindFirstChild('Hair1'):Destroy()
		hair2.Parent = character
	end
	if character:FindFirstChild('Hair3')== nil then
		character:FindFirstChild('Hair3'):Destroy()
		
		hair3.Parent = character
	end
	if character:FindFirstChild('Hair4')== nil then
		character:FindFirstChild('Hair4'):Destroy()
		hair4.Parent = character
	end
	if character:FindFirstChild('Hair5') == nil then
		character:FindFirstChild('Hair5'):Destroy()
		hair5.Parent = character
	end
	if character:FindFirstChild('Hair6') == nil then
		character:FindFirstChild('Hair6'):Destroy()
		hair6.Parent = character
	end
	if character:FindFirstChild('Hair7') == nil then
		character:FindFirstChild('Hair7'):Destroy()
		hair7.Parent = character
	end
	
end)

1 comment

0

Why do you have so many == nil for nothing?

1 answer

Have you ever heard of elseif? Also what is the error? What is happening instead? Why are you using so many nils?

Try reducing the amount of lines that you have used.

This discussion is preserved as it was. New answers, comments, and votes are closed.