RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make tictactoe"
-- ScripterAI can only help with scripting as of now so here's a script for a basic tic tac toe game local player1 = game.Players.Player1 local player2 = game.Players.Player2 local currentTurn = player1 local board = { {" ", " ", " "}, {" ", " ", " "}, {" ", " ", " "} } function printBoard() print(board[1][1] .. "|" .. board[1][2] .. "|" .. board[1][3]) print("-----") print(board[2][1] .. "|" .. board[2][2] .. "|" .. board[2][3]) print("-----") print(board[3][1] .. "|" .. board[3][2] .. "|" .. board[3][3]) end function checkWin() for i = 1, 3 do if board[i][1] == board[i][2] and board[i][2] == board[i][3] and board[i][1] ~= " " then return true end if board[1][i] == board[2][i] and board[2][i] == board[3][i] and board[1][i] ~= " " then return true end end if board[1][1] == board[2][2] and board[2][2] == board[3][3] and board[1][1] ~= " " then return true end if board[1][3] == board[2][2] and board[2][2] == board[3][1] and board[1][3] ~= " " then return true end return false end function makeMove(player, row, col) if board[row][col] == " " then board[row][col] = player.Name printBoard() if checkWin() then print(player.Name .. " wins!") else if player == player1 then currentTurn = player2 else currentTurn = player1 end print("It's " .. currentTurn.Name .. "'s turn.") end else print("That space is already taken.") end end print("Welcome to Tic Tac Toe!") printBoard() print("It's " .. currentTurn.Name .. "'s turn.") game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) Character.Humanoid.Died:Connect(function() if Player == currentTurn then if Player == player1 then currentTurn = player2 else currentTurn = player1 end print("It's " .. currentTurn.Name .. "'s turn.") end end) end) end) game.ReplicatedStorage.MakeMove.OnServerInvoke = function(Player, row, col) if Player == currentTurn then makeMove(Player, row, col) else print("It's not your turn.") end end