local s="\088"local e="\088"local n=0 local T=true function resetGame()if e=="\088"then e="\079"else e="\088"end s=e n=0 for s=0,1,.02 do for e=1,9,1 do if script.Parent["\088"..e].Transparency~=1 then script.Parent["\088"..e].Transparency=s end if script.Parent["\079"..e].Transparency~=1 then script.Parent["\079"..e].Transparency=s end end for e=1,8,1 do if script.Parent["\087\105\110"..e].Transparency~=1 then script.Parent["\087\105\110"..e].Transparency=s end end if script.Parent.Cat.Transparency~=1 then script.Parent.Cat.Transparency=s end wait()end for s=1,9,1 do script.Parent["\088"..s].Transparency=1 script.Parent["\079"..s].Transparency=1 end for s=1,8,1 do script.Parent["\087\105\110"..s].Transparency=1 end script.Parent.Cat.Transparency=1 T=true end function winGame(e)T=false if s=="\088"then print("\088 \119\111\110\033")else print("\079 \119\111\110\033")end script.Parent["\087\105\110"..e].Transparency=0 wait(2)resetGame()end function tieGame()T=false print("\073\116 \119\097\115 \097 \116\105\101\033")script.Parent.Cat.Transparency=0 wait(2)resetGame()end function checkForWin()if script.Parent[s..1].Transparency==0 and(script.Parent[s..2].Transparency==0 and script.Parent[s..3].Transparency==0)then winGame(4)return elseif script.Parent[s..1].Transparency==0 and(script.Parent[s..4].Transparency==0 and script.Parent[s..7].Transparency==0)then winGame(1)return elseif script.Parent[s..1].Transparency==0 and(script.Parent[s..5].Transparency==0 and script.Parent[s..9].Transparency==0)then winGame(7)return elseif script.Parent[s..2].Transparency==0 and(script.Parent[s..5].Transparency==0 and script.Parent[s..8].Transparency==0)then winGame(2)return elseif script.Parent[s..3].Transparency==0 and(script.Parent[s..5].Transparency==0 and script.Parent[s..7].Transparency==0)then winGame(8)return elseif script.Parent[s..3].Transparency==0 and(script.Parent[s..6].Transparency==0 and script.Parent[s..9].Transparency==0)then winGame(3)return elseif script.Parent[s..4].Transparency==0 and(script.Parent[s..5].Transparency==0 and script.Parent[s..6].Transparency==0)then winGame(5)return elseif script.Parent[s..7].Transparency==0 and(script.Parent[s..8].Transparency==0 and script.Parent[s..9].Transparency==0)then winGame(6)return elseif n==9 then tieGame()end end function setPiece(e)if not getSpotState(e)and T then script.Parent[s..e].Transparency=0 n=n+1 wait()checkForWin()if s=="\088"then s="\079"else s="\088"end end end function getSpotState(s)if script.Parent["\088"..s].Transparency==0 then return"\088"elseif script.Parent["\079"..s].Transparency==0 then return"\079"else return false end end for s=1,9,1 do script.Parent["\068\101\116\101\099\116\111\114"..s].ClickDetector.MouseClick:connect(function()setPiece(s)end)end
--created on December 2, 2016 at 11:44 pm

local currentTurn = "X"
local lastFirstMove = "X"
local moveCount = 0
local isGameReady = true

function resetGame()
	if lastFirstMove == "X" then
		lastFirstMove = "O"
	else
		lastFirstMove = "X"
	end
	currentTurn = lastFirstMove
	moveCount = 0
	for j = 0, 1, 0.02 do
		for i = 1, 9 do
			if script.Parent["X" .. i].Transparency ~= 1 then
				script.Parent["X" .. i].Transparency = j
			end
			if script.Parent["O" .. i].Transparency ~= 1 then
				script.Parent["O" .. i].Transparency = j
			end
		end
		for i = 1, 8 do
			if script.Parent["Win" .. i].Transparency ~= 1 then
				script.Parent["Win" .. i].Transparency = j
			end
		end
		if script.Parent.Cat.Transparency ~= 1 then
			script.Parent.Cat.Transparency = j
		end
		wait()
	end
	for i = 1, 9 do
		script.Parent["X" .. i].Transparency = 1
		script.Parent["O" .. i].Transparency = 1
	end
	for i = 1, 8 do
		script.Parent["Win" .. i].Transparency = 1
	end
	script.Parent.Cat.Transparency = 1
	isGameReady = true
end

function winGame(num)
	isGameReady = false
	if currentTurn == "X" then
		print("X won!")
	else
		print("O won!")
	end
	script.Parent["Win" .. num].Transparency = 0
	wait(2)
	resetGame()
end

function tieGame()
	isGameReady = false
	print("It was a tie!")
	script.Parent.Cat.Transparency = 0
	wait(2)
	resetGame()
end

function checkForWin()
	if
		script.Parent[currentTurn .. 1].Transparency == 0
		and script.Parent[currentTurn .. 2].Transparency == 0
		and script.Parent[currentTurn .. 3].Transparency == 0
	then
		winGame(4)
		return
	elseif
		script.Parent[currentTurn .. 1].Transparency == 0
		and script.Parent[currentTurn .. 4].Transparency == 0
		and script.Parent[currentTurn .. 7].Transparency == 0
	then
		winGame(1)
		return
	elseif
		script.Parent[currentTurn .. 1].Transparency == 0
		and script.Parent[currentTurn .. 5].Transparency == 0
		and script.Parent[currentTurn .. 9].Transparency == 0
	then
		winGame(7)
		return
	elseif
		script.Parent[currentTurn .. 2].Transparency == 0
		and script.Parent[currentTurn .. 5].Transparency == 0
		and script.Parent[currentTurn .. 8].Transparency == 0
	then
		winGame(2)
		return
	elseif
		script.Parent[currentTurn .. 3].Transparency == 0
		and script.Parent[currentTurn .. 5].Transparency == 0
		and script.Parent[currentTurn .. 7].Transparency == 0
	then
		winGame(8)
		return
	elseif
		script.Parent[currentTurn .. 3].Transparency == 0
		and script.Parent[currentTurn .. 6].Transparency == 0
		and script.Parent[currentTurn .. 9].Transparency == 0
	then
		winGame(3)
		return
	elseif
		script.Parent[currentTurn .. 4].Transparency == 0
		and script.Parent[currentTurn .. 5].Transparency == 0
		and script.Parent[currentTurn .. 6].Transparency == 0
	then
		winGame(5)
		return
	elseif
		script.Parent[currentTurn .. 7].Transparency == 0
		and script.Parent[currentTurn .. 8].Transparency == 0
		and script.Parent[currentTurn .. 9].Transparency == 0
	then
		winGame(6)
		return
	elseif moveCount == 9 then
		tieGame()
	end
end

function setPiece(num)
	if not getSpotState(num) and isGameReady then
		script.Parent[currentTurn .. num].Transparency = 0
		moveCount = moveCount + 1
		wait()
		checkForWin()
		if currentTurn == "X" then
			currentTurn = "O"
		else
			currentTurn = "X"
		end
	end
end

function getSpotState(num)
	if script.Parent["X" .. num].Transparency == 0 then
		return "X"
	elseif script.Parent["O" .. num].Transparency == 0 then
		return "O"
	else
		return false
	end
end

for i = 1, 9 do
	script.Parent["Detector" .. i].ClickDetector.MouseClick:connect(function()
		setPiece(i)
	end)
end
