How can i prevent this loop from happening four times?

I’m working on character customization for my game and I’ve run into a problem that I believe has something to do with players when they choose a beard. I have a print that prints the key and value within the loop. This prints four times which I assume is the problem. There are no errors, but it just stops the script and prevents it from going any further. Whether or not you choose a beard or not, nothing happens which is why I’m here. I’ve written out this code below. If you find my mistake, please let me know what I did wrong and how I can prevent it from happening again if you have questions feel free to comment :slightly_smiling_face:.

clientServer.OnServerEvent:Connect(function(plr, msg, selectedItems, colors)
	local rawData = dataModule.pullDecoded(plr, dataModule.grabFolder(plr))
	local id = plr.masterFolder.basicData.selectedSlot.Value
	if msg == "submit" then
		serverClient:FireClient(plr, "fadeAndNext") = selectedItems["hair"] = selectedItems["beard"] = selectedItems["face"] = selectedItems["skintone"]

		for key,val in pairs(selectedItems) do		
			local find = items:FindFirstChild(key)
				for key, item in pairs(selectedItems) do
				print(key .. ", ".. val)

			if tostring(find) == "hair" then					
				local hair = find:FindFirstChild(colors.hairColor):FindFirstChild(val):Clone()
				local weld ="WeldConstraint", plr.Character.Head)
				weld.Part0 = plr.Character.Head
				weld.Part1 = hair

				hair.CFrame = plr.Character.Head.CFrame
				hair.Parent = plr.Character.accessories
				hair.Transparency = 0

			elseif tostring(find) == "beard" then				
				if selectedItems.beard.Value ~= nil then
				local beard = find:FindFirstChild(colors.beardColor):FindFirstChild(val):Clone()
				local weld ="WeldConstraint", plr.Character.Head)
				weld.Part0 = plr.Character.Head
				weld.Part1 = beard

				beard.CFrame = plr.Character.Head.CFrame
				beard.Parent = plr.Character.accessories

			elseif tostring(find) == "face" then			
				local face = plr.Character.Head.face
				local new = find:FindFirstChild(

			elseif tostring(find) == "skintone" then				
				local tone = find:FindFirstChild(val)

				for _,v in pairs(plr.Character:GetChildren()) do
					if v.ClassName == "Part" then
						v.BrickColor = tone.Value

	local newData = dataModule.EncodeUpdatedRaw(rawData)
	dataModule.pushSave(plr, newData, "file".. id)


Are you able to share the script that’s providing the 2nd argument on the localscript?

It’s printing 4 times because supposedly, there are 4 items in selectedItems, received from the client.

Once the player has selected all of their items. It passes a table through with the selected items if that makes sense. Basically it looks like clientServer:FireServer("submit", selectedItems). Not sure what I did for colors but I’ll check and see.

Here is the code for firing to the server.

	local selectedItems = {
		["hair"] = hair.selected.Value,
		["beard"] = beard.selected.Value,
		["face"] = faces.selected.Value,
		["skintone"] = skintone.selected.Value

	local colors = {
		["hairColor"] = hair.color.Value,
		["beardColor"] = beard.color.Value	
	if hair.selected.Value ~= "" and faces.selected.Value ~= "" and skintone.selected.Value ~= "" then
		clientServer:FireServer("submit", selectedItems, colors)
		print("player doesnt have a required value.")