local x="\088"local t="\088"local Z=0 local o=true function resetGame()if t=="\088"then t="\079"else t="\088"end x=t Z=0 for x=0,1,.02 do for t=1,9,1 do if script.Parent["\088"..t].Transparency~=1 then script.Parent["\088"..t].Transparency=x end if script.Parent["\079"..t].Transparency~=1 then script.Parent["\079"..t].Transparency=x end end for t=1,8,1 do if script.Parent["\087\105\110"..t].Transparency~=1 then script.Parent["\087\105\110"..t].Transparency=x end end if script.Parent.Cat.Transparency~=1 then script.Parent.Cat.Transparency=x end wait()end for x=1,9,1 do script.Parent["\088"..x].Transparency=1 script.Parent["\079"..x].Transparency=1 end for x=1,8,1 do script.Parent["\087\105\110"..x].Transparency=1 end script.Parent.Cat.Transparency=1 o=true end function winGame(t)o=false if x=="\088"then else end script.Parent["\087\105\110"..t].Transparency=0 wait(2)resetGame()end function tieGame()o=false script.Parent.Cat.Transparency=0 wait(2)resetGame()end function checkForWin()if script.Parent[x..1].Transparency==0 and(script.Parent[x..2].Transparency==0 and script.Parent[x..3].Transparency==0)then winGame(4)return elseif script.Parent[x..1].Transparency==0 and(script.Parent[x..4].Transparency==0 and script.Parent[x..7].Transparency==0)then winGame(1)return elseif script.Parent[x..1].Transparency==0 and(script.Parent[x..5].Transparency==0 and script.Parent[x..9].Transparency==0)then winGame(7)return elseif script.Parent[x..2].Transparency==0 and(script.Parent[x..5].Transparency==0 and script.Parent[x..8].Transparency==0)then winGame(2)return elseif script.Parent[x..3].Transparency==0 and(script.Parent[x..5].Transparency==0 and script.Parent[x..7].Transparency==0)then winGame(8)return elseif script.Parent[x..3].Transparency==0 and(script.Parent[x..6].Transparency==0 and script.Parent[x..9].Transparency==0)then winGame(3)return elseif script.Parent[x..4].Transparency==0 and(script.Parent[x..5].Transparency==0 and script.Parent[x..6].Transparency==0)then winGame(5)return elseif script.Parent[x..7].Transparency==0 and(script.Parent[x..8].Transparency==0 and script.Parent[x..9].Transparency==0)then winGame(6)return elseif Z==9 then tieGame()end end function setPiece(t)if not getSpotState(t)and o then script.Parent[x..t].Transparency=0 Z=Z+1 wait()checkForWin()if x=="\088"then x="\079"else x="\088"end end end function getSpotState(x)if script.Parent["\088"..x].Transparency==0 then return"\088"elseif script.Parent["\079"..x].Transparency==0 then return"\079"else return false end end for x=1,9,1 do script.Parent["\068\101\116\101\099\116\111\114"..x].ClickDetector.MouseClick:connect(function()setPiece(x)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
	else
	end
	script.Parent["Win" .. num].Transparency = 0
	wait(2)
	resetGame()
end

function tieGame()
	isGameReady = false
	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
