Run it
Copy the script and paste it into your executor.
isOpen =
gameRunning =
gamePaused =
score =
level =
linesCleared =
boardWidth =
boardHeight =
board = {}
nextPiece =
tetriminos = {
{
{{,,,}, {,,,}, {,,,}, {,,,}},
color = .(, , )
},
{
{{,,}, {,,}, {,,}},
color = .(, , )
},
{
{{,,}, {,,}, {,,}},
color = .(, , )
},
{
{{,}, {,}},
color = .(, , )
},
{
{{,,}, {,,}, {,,}},
color = .(, , )
},
{
{{,,}, {,,}, {,,}},
color = .(, , )
},
{
{{,,}, {,,}, {,,}},
color = .(, , )
}
}
currentPiece = {
shape = {},
x = ,
y = ,
color = .(, , ),
rotation =
}
SoundService = :()
BGM = .()
GUICloseSound = .()
LineClearSound = .()
BGM.SoundId =
BGM.Name =
BGM.Looped =
BGM.Volume =
BGM.Parent = SoundService
GUICloseSound.SoundId =
GUICloseSound.Name =
GUICloseSound.Volume =
GUICloseSound.Parent = SoundService
LineClearSound.SoundId =
LineClearSound.Name =
LineClearSound.Volume =
LineClearSound.Parent = SoundService
ScreenGui = .()
ScreenGui.Name =
ScreenGui.Parent = .Players.LocalPlayer:()
MainFrame = .()
MainFrame.Name =
MainFrame.Size = .(, , , )
MainFrame.Position = .(, -, , -)
MainFrame.BackgroundColor3 = .(, , )
MainFrame.BorderSizePixel =
MainFrame.Visible =
MainFrame.Parent = ScreenGui
TitleBar = .()
TitleBar.Name =
TitleBar.Size = .(, , , )
TitleBar.BackgroundColor3 = .(, , )
TitleBar.Parent = MainFrame
TitleLabel = .()
TitleLabel.Name =
TitleLabel.Size = .(, -, , )
TitleLabel.Position = .(, , , )
TitleLabel.BackgroundTransparency =
TitleLabel.Text =
TitleLabel.TextColor3 = .(, , )
TitleLabel.TextSize =
TitleLabel.Font = .Font.GothamBold
TitleLabel.TextXAlignment = .TextXAlignment.Left
TitleLabel.Parent = TitleBar
CloseButton = .()
CloseButton.Name =
CloseButton.Size = .(, , , )
CloseButton.Position = .(, -, , )
CloseButton.BackgroundColor3 = .(, , )
CloseButton.Text =
CloseButton.TextColor3 = .(, , )
CloseButton.TextSize =
CloseButton.Font = .Font.GothamBold
CloseButton.Parent = TitleBar
GameFrame = .()
GameFrame.Name =
GameFrame.Size = .(, , , )
GameFrame.Position = .(, , , )
GameFrame.BackgroundColor3 = .(, , )
GameFrame.BorderSizePixel =
GameFrame.BorderColor3 = .(, , )
GameFrame.Parent = MainFrame
RightPanel = .()
RightPanel.Name =
RightPanel.Size = .(, , , )
RightPanel.Position = .(, , , )
RightPanel.BackgroundColor3 = .(, , )
RightPanel.BorderSizePixel =
RightPanel.Parent = MainFrame
ScorePanel = .()
ScorePanel.Name =
ScorePanel.Size = .(, -, , )
ScorePanel.Position = .(, , , )
ScorePanel.BackgroundColor3 = .(, , )
ScorePanel.BorderSizePixel =
ScorePanel.BorderColor3 = .(, , )
ScorePanel.Parent = RightPanel
ScoreTitle = .()
ScoreTitle.Name =
ScoreTitle.Size = .(, , , )
ScoreTitle.Position = .(, , , )
ScoreTitle.BackgroundColor3 = .(, , )
ScoreTitle.Text =
ScoreTitle.TextColor3 = .(, , )
ScoreTitle.TextSize =
ScoreTitle.Font = .Font.GothamBold
ScoreTitle.Parent = ScorePanel
ScoreLabel = .()
ScoreLabel.Name =
ScoreLabel.Size = .(, -, , )
ScoreLabel.Position = .(, , , )
ScoreLabel.BackgroundTransparency =
ScoreLabel.Text =
ScoreLabel.TextColor3 = .(, , )
ScoreLabel.TextSize =
ScoreLabel.Font = .Font.Gotham
ScoreLabel.TextXAlignment = .TextXAlignment.Left
ScoreLabel.Parent = ScorePanel
LevelLabel = .()
LevelLabel.Name =
LevelLabel.Size = .(, -, , )
LevelLabel.Position = .(, , , )
LevelLabel.BackgroundTransparency =
LevelLabel.Text =
LevelLabel.TextColor3 = .(, , )
LevelLabel.TextSize =
LevelLabel.Font = .Font.Gotham
LevelLabel.TextXAlignment = .TextXAlignment.Left
LevelLabel.Parent = ScorePanel
LinesLabel = .()
LinesLabel.Name =
LinesLabel.Size = .(, -, , )
LinesLabel.Position = .(, , , )
LinesLabel.BackgroundTransparency =
LinesLabel.Text =
LinesLabel.TextColor3 = .(, , )
LinesLabel.TextSize =
LinesLabel.Font = .Font.Gotham
LinesLabel.TextXAlignment = .TextXAlignment.Left
LinesLabel.Parent = ScorePanel
ControlsPanel = .()
ControlsPanel.Name =
ControlsPanel.Size = .(, -, , )
ControlsPanel.Position = .(, , , -)
ControlsPanel.BackgroundColor3 = .(, , )
ControlsPanel.BorderSizePixel =
ControlsPanel.BorderColor3 = .(, , )
ControlsPanel.Parent = RightPanel
ControlsTitle = .()
ControlsTitle.Name =
ControlsTitle.Size = .(, , , )
ControlsTitle.Position = .(, , , )
ControlsTitle.BackgroundColor3 = .(, , )
ControlsTitle.Text =
ControlsTitle.TextColor3 = .(, , )
ControlsTitle.TextSize =
ControlsTitle.Font = .Font.GothamBold
ControlsTitle.Parent = ControlsPanel
ButtonGrid = .()
ButtonGrid.Name =
ButtonGrid.Size = .(, -, , )
ButtonGrid.Position = .(, , , )
ButtonGrid.BackgroundTransparency =
ButtonGrid.Parent = ControlsPanel
LeftButton = .()
LeftButton.Name =
LeftButton.Size = .(, , , )
LeftButton.Position = .(, , , -)
LeftButton.BackgroundColor3 = .(, , )
LeftButton.Text =
LeftButton.TextColor3 = .(, , )
LeftButton.TextSize =
LeftButton.Font = .Font.GothamBold
LeftButton.Parent = ButtonGrid
DownButton = .()
DownButton.Name =
DownButton.Size = .(, , , )
DownButton.Position = .(, -, , -)
DownButton.BackgroundColor3 = .(, , )
DownButton.Text =
DownButton.TextColor3 = .(, , )
DownButton.TextSize =
DownButton.Font = .Font.GothamBold
DownButton.Parent = ButtonGrid
RightButton = .()
RightButton.Name =
RightButton.Size = .(, , , )
RightButton.Position = .(, -, , -)
RightButton.BackgroundColor3 = .(, , )
RightButton.Text =
RightButton.TextColor3 = .(, , )
RightButton.TextSize =
RightButton.Font = .Font.GothamBold
RightButton.Parent = ButtonGrid
RotateButton = .()
RotateButton.Name =
RotateButton.Size = .(, -, , )
RotateButton.Position = .(, , , )
RotateButton.BackgroundColor3 = .(, , )
RotateButton.Text =
RotateButton.TextColor3 = .(, , )
RotateButton.TextSize =
RotateButton.Font = .Font.Gotham
RotateButton.Parent = ControlsPanel
SoundToggleButton = .()
SoundToggleButton.Name =
SoundToggleButton.Size = .(, -, , )
SoundToggleButton.Position = .(, , , )
SoundToggleButton.BackgroundColor3 = .(, , )
SoundToggleButton.Text =
SoundToggleButton.TextColor3 = .(, , )
SoundToggleButton.TextSize =
SoundToggleButton.Font = .Font.Gotham
SoundToggleButton.Parent = ControlsPanel
StartPauseButton = .()
StartPauseButton.Name =
StartPauseButton.Size = .(, -, , )
StartPauseButton.Position = .(, , , -)
StartPauseButton.BackgroundColor3 = .(, , )
StartPauseButton.Text =
StartPauseButton.TextColor3 = .(, , )
StartPauseButton.TextSize =
StartPauseButton.Font = .Font.GothamBold
StartPauseButton.Parent = ControlsPanel
bgmEnabled =
()
bgmEnabled = bgmEnabled
bgmEnabled
SoundToggleButton.Text =
SoundToggleButton.BackgroundColor3 = .(, , )
gameRunning gamePaused
BGM:()
SoundToggleButton.Text =
SoundToggleButton.BackgroundColor3 = .(, , )
BGM:()
BoardFrame = .()
BoardFrame.Name =
BoardFrame.Size = .(, -, , -)
BoardFrame.Position = .(, , , )
BoardFrame.BackgroundColor3 = .(, , )
BoardFrame.BorderSizePixel =
BoardFrame.Parent = GameFrame
boardCells = {}
cellSize =
()
board = {}
y = , boardHeight
board[y] = {}
x = , boardWidth
board[y][x] =
y = , boardHeight
boardCells[y] = {}
x = , boardWidth
cell = .()
cell.Name = .. x .. .. y
cell.Size = .(, cellSize, , cellSize)
cell.Position = .(, (x-)*cellSize, , (y-)*cellSize)
cell.BackgroundColor3 = .(, , )
cell.BorderSizePixel =
cell.BorderColor3 = .(, , )
cell.Parent = BoardFrame
boardCells[y][x] = cell
()
pieceIndex = .(, #tetriminos)
pieceData = tetriminos[pieceIndex]
currentPiece.shape = pieceData[]
currentPiece.color = pieceData.color
currentPiece.x = .(boardWidth/) - .(#currentPiece.shape[]/)
currentPiece.y =
currentPiece.rotation =
(currentPiece.x, currentPiece.y, currentPiece.shape)
()
(x, y, shape)
row = , #shape
col = , #shape[row]
shape[row][col] ~=
boardX = x + col -
boardY = y + row -
boardX < boardX > boardWidth boardY > boardHeight
boardY > board[boardY] board[boardY][boardX] ~=
()
row = , #currentPiece.shape
col = , #currentPiece.shape[row]
currentPiece.shape[row][col] ~=
boardX = currentPiece.x + col -
boardY = currentPiece.y + row -
boardY >
board[boardY][boardX] =
boardCells[boardY][boardX].BackgroundColor3 = currentPiece.color
()
()
()
linesToClear = {}
y = , boardHeight
lineFull =
x = , boardWidth
board[y][x] ==
lineFull =
lineFull
.(linesToClear, y)
#linesToClear >
i, y (linesToClear)
x = , boardWidth
board[y][x] =
yy = y, , -
x = , boardWidth
board[yy][x] = board[yy-][x]
x = , boardWidth
board[][x] =
baseScore =
#linesToClear ==
baseScore =
#linesToClear ==
baseScore =
#linesToClear ==
baseScore =
#linesToClear ==
baseScore =
score = score + baseScore * level
linesCleared = linesCleared + #linesToClear
level = .(linesCleared / ) +
ScoreLabel.Text = .. (score)
LevelLabel.Text = .. (level)
LinesLabel.Text = .. (linesCleared)
gameRunning gamePaused
LineClearSound:()
()
y = , boardHeight
x = , boardWidth
board[y][x] ==
boardCells[y][x].BackgroundColor3 = .(, , )
gameRunning gamePaused
row = , #currentPiece.shape
col = , #currentPiece.shape[row]
currentPiece.shape[row][col] ~=
boardX = currentPiece.x + col -
boardY = currentPiece.y + row -
boardY > boardY <= boardHeight boardX > boardX <= boardWidth
boardCells[boardY] boardCells[boardY][boardX]
boardCells[boardY][boardX].BackgroundColor3 = currentPiece.color
(dx, dy)
gameRunning gamePaused
(currentPiece.x + dx, currentPiece.y + dy, currentPiece.shape)
currentPiece.x = currentPiece.x + dx
currentPiece.y = currentPiece.y + dy
()
dy >
()
()
()
gameRunning gamePaused
currentShape = currentPiece.shape
newShape = {}
i = , #currentShape[]
newShape[i] = {}
j = , #currentShape
newShape[i][j] = currentShape[#currentShape - j + ][i]
(currentPiece.x, currentPiece.y, newShape)
currentPiece.shape = newShape
()
()
gameRunning =
StartPauseButton.Text =
StartPauseButton.BackgroundColor3 = .(, , )
BGM:()
message = .()
message.Name =
message.Size = .(, , , )
message.Position = .(, , , -)
message.BackgroundColor3 = .(, , )
message.BackgroundTransparency =
message.Text = .. (score) ..
message.TextColor3 = .(, , )
message.TextSize =
message.Font = .Font.GothamBold
message.ZIndex =
message.Parent = BoardFrame
()
BoardFrame:()
BoardFrame.GameOverMessage:()
()
gameRunning =
StartPauseButton.Text =
StartPauseButton.BackgroundColor3 = .(, , )
bgmEnabled
BGM:()
()
score =
level =
linesCleared =
ScoreLabel.Text =
LevelLabel.Text =
LinesLabel.Text =
BoardFrame:()
BoardFrame.GameOverMessage:()
()
()
()
lastUpdate = ()
fallTime =
()
gameRunning gamePaused
currentTime = ()
currentTime - lastUpdate > fallTime / level
(, )
lastUpdate = currentTime
CloseButton.MouseButton1Click:(()
GUICloseSound:()
BGM:()
MainFrame.Visible =
isOpen =
OpenButton.Visible =
)
StartPauseButton.MouseButton1Click:(()
gameRunning
gameRunning =
gamePaused =
StartPauseButton.Text =
StartPauseButton.BackgroundColor3 = .(, , )
bgmEnabled
BGM:()
score ==
()
gamePaused
gamePaused =
StartPauseButton.Text =
StartPauseButton.BackgroundColor3 = .(, , )
BGM:()
gamePaused =
StartPauseButton.Text =
StartPauseButton.BackgroundColor3 = .(, , )
bgmEnabled
BGM:()
)
LeftButton.MouseButton1Click:(()
(-, )
)
RightButton.MouseButton1Click:(()
(, )
)
DownButton.MouseButton1Click:(()
(, )
)
RotateButton.MouseButton1Click:(()
()
)
SoundToggleButton.MouseButton1Click:(()
()
)
UserInputService = :()
UserInputService.InputBegan:((input)
gameRunning gamePaused
input.KeyCode == .KeyCode.Left
(-, )
input.KeyCode == .KeyCode.Right
(, )
input.KeyCode == .KeyCode.Down
(, )
input.KeyCode == .KeyCode.R
()
input.KeyCode == .KeyCode.M
()
)
:().RenderStepped:(gameLoop)
OpenButton = .()
OpenButton.Name =
OpenButton.Size = .(, , , )
OpenButton.Position = .(, -, , -)
OpenButton.BackgroundColor3 = .(, , )
OpenButton.BackgroundTransparency =
OpenButton.Text =
OpenButton.TextColor3 = .(, , )
OpenButton.TextSize =
OpenButton.Font = .Font.GothamBold
OpenButton.Parent = ScreenGui
OpenButtonGlow = .()
OpenButtonGlow.Name =
OpenButtonGlow.Color = .(, , )
OpenButtonGlow.Thickness =
OpenButtonGlow.Parent = OpenButton
OpenButtonCorner = .()
OpenButtonCorner.Name =
OpenButtonCorner.CornerRadius = .(, )
OpenButtonCorner.Parent = OpenButton
OpenButtonText = .()
OpenButtonText.Name =
OpenButtonText.Size = .(, , , )
OpenButtonText.Position = .(-, , , )
OpenButtonText.BackgroundTransparency =
OpenButtonText.Text =
OpenButtonText.TextColor3 = .(, , )
OpenButtonText.TextSize =
OpenButtonText.Font = .Font.Gotham
OpenButtonText.Parent = OpenButton
dragging =
dragInput
dragStart
startPos
(input)
delta = input.Position - dragStart
OpenButton.Position = .(
startPos.X.Scale,
startPos.X.Offset + delta.X,
startPos.Y.Scale,
startPos.Y.Offset + delta.Y
)
OpenButton.InputBegan:((input)
input.UserInputType == .UserInputType.MouseButton1 input.UserInputType == .UserInputType.Touch
dragging =
dragStart = input.Position
startPos = OpenButton.Position
OpenButton.BackgroundTransparency =
OpenButtonGlow.Color = .(, , )
OpenButton.TextColor3 = .(, , )
OpenButtonText.TextColor3 = .(, , )
input.Changed:(()
input.UserInputState == .UserInputState.End
dragging =
OpenButton.BackgroundTransparency =
OpenButtonGlow.Color = .(, , )
OpenButton.TextColor3 = .(, , )
OpenButtonText.TextColor3 = .(, , )
)
)
OpenButton.InputChanged:((input)
input.UserInputType == .UserInputType.MouseMovement input.UserInputType == .UserInputType.Touch
dragInput = input
)
UserInputService.InputChanged:((input)
input == dragInput dragging
(input)
)
OpenButton.MouseButton1Click:(()
dragging
isOpen = isOpen
MainFrame.Visible = isOpen
OpenButton.Visible = isOpen
isOpen #board ==
()
()
()
)
CloseButton.MouseButton1Click:(()
GUICloseSound:()
MainFrame.Visible =
isOpen =
OpenButton.Visible =
)
OpenButton.MouseEnter:(()
dragging
OpenButton.BackgroundTransparency =
OpenButtonGlow.Color = .(, , )
OpenButton.TextColor3 = .(, , )
OpenButtonText.TextColor3 = .(, , )
)
OpenButton.MouseLeave:(()
dragging
OpenButton.BackgroundTransparency =
OpenButtonGlow.Color = .(, , )
OpenButton.TextColor3 = .(, , )
OpenButtonText.TextColor3 = .(, , )
)
()
()
()
()
()
()
()
:().LocalPlayer.CharacterAdded:(()
BGM:()
GUICloseSound:()
LineClearSound:()
)
Universal