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

why does this script delete the face that is there the first time but not the second time?

value.Changed:connect(function()
print(faces[value.Value])
	if value.Value == 1 then
		local annoyedFace = faceFolder:WaitForChild'AnnoyedFace':Clone()
		for i,v in pairs(faceFinder) do
			if v.ClassName == 'Decal' then
				
				v:Destroy()
				wait()
			end
		end
		annoyedFace.Parent = head
		
	end 
	if value.Value == 2 then
		local awkwardFace = faceFolder:WaitForChild'AwkwardFace':Clone()
		
		for i,v in pairs(faceFinder) do
			if v.ClassName == 'Decal' then
				
				v:Destroy()
				wait()
			end
		end
		
		awkwardFace.Parent = head
	end 
	
	
end)


if you dont understand the header why does the for loop only run once?

1 answer

You repeat a lot of your code so I would 1st re-think it:-

-- the function to remove all of the decals
function rmDecal(face)
	for i,v in pairs(face) do
		if v.ClassName == 'Decal' then v:Destroy() end
		wait()
	end		
end

-- a function to clone and add the face to the head 
function clnFace(faceName, par) 
	 faceFolder:WaitForChild(faceName):Clone().Parent = par
end

value.Changed:connect(function(newValue) -- there is a paramater which you chould use 
	print('new value is', newValue)
	-- use elseif as we only want one of these to run
	if newValue == 1 then rmDecal(faceFinder) clnFace('AnnoyedFace', head)
	elseif newValue == 2 then rmDecal(faceFinder) clnFace('AwkwardFace', head)
	end
end)

I have change a lot of you code around as you had a lot of duplicated code, pls comment if you do not understand what I have changed and why.

Pls also comment if this does not solve the problem as it may be how you are getting the 'faceFinder' variable, if so please include the code where the 'faceFinder' is from.

Hope this helps.

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