-- for quick setting-back of face

local oldFace = nil
local oldFaceTexture = nil

local debounce = false
function changeFace(torso)
	if debounce then return end
	debounce = true 

	oldFace = nil
	oldFaceTexture = nil

	local char = torso.Parent
	if char then
		local charHead = char:FindFirstChild("Head")
		if charHead then
			local charFace = charHead:FindFirstChild("face")
			if charFace then
				oldFaceTexture = charFace.Texture
				charFace.Texture = "http://www.roblox.com/asset/?id="..tostring(toiletFace[math.random(1, #toiletFace)])
				oldFace = charFace
			end
		end
	end
end

function checkForNewSitter(newChild)
	if newChild:IsA("Weld") and newChild.Name == "SeatWeld" then
		if newChild.Part0 == toilet then changeFace(newChild.Part1)
		else changeFace(newChild.Part0) end
	end
end

function checkForFaceRelease(child)
	if child:IsA("Weld") and child.Name == "SeatWeld" then
		if oldFace and oldFaceTexture then
			oldFace.Texture = oldFaceTexture
			oldFace = nil
			oldFaceTexture = nil
		end

		debounce = false
	end
end

toilet.ChildAdded:connect(checkForNewSitter)
toilet.ChildRemoved:connect(checkForFaceRelease)
