I have 16*12 to fill. Is it too much for it?
Here’s the script:
local Size = {16,12}
local MineChance = 25
local MiniumMines = Size[1]*Size[2]/4
local MaxiumMines = Size[1]*Size[2]/3
local CANSTART = false
local Service = game:GetService("TweenService")
local Steps = 0
local COLORTABLE = {Color3.fromRGB(0, 85, 255),Color3.fromRGB(0, 170, 0),Color3.fromRGB(255, 0, 0),Color3.fromRGB(170, 0, 127),Color3.fromRGB(170, 0, 0),Color3.fromRGB(0, 255, 255),Color3.fromRGB(27, 42, 53),Color3.fromRGB(91, 93, 105)}
local UIS = game:GetService("UserInputService")
function Clear()
script.Parent.Tiles:ClearAllChildren()
end
function Generate(N)
repeat
repeat ---- Generating Mines, repeat untill reach MiniumMines ----
for i = 1,Size[1]*Size[2] do
table.insert(TABLE,#TABLE+1,0)
end
local MineCount = 0
for i = 1,#TABLE do
local INDEX = math.random(0,100)
if INDEX <= MineChance and i ~= N then
TABLE[i] = 9
MineCount = MineCount + 1
end
end
if MineCount < MiniumMines or MineCount > MaxiumMines then
TABLE = {}
end
until MineCount >= MiniumMines and MineCount <= MaxiumMines
---- Number Indicators ----
for i = 1,#TABLE do
local A = 0
if TABLE[i] ~= 9 then
if TABLE[i-17] == 9 then
A = A + 1
end
if TABLE[i-16] == 9 then
A = A + 1
end
if TABLE[i-15] == 9 then
A = A + 1
end
if TABLE[i-1] == 9 then
A = A + 1
end
if TABLE[i+1] == 9 then
A = A + 1
end
if TABLE[i+15] == 9 then
A = A + 1
end
if TABLE[i+16] == 9 then
A = A + 1
end
if TABLE[i+17] == 9 then
A = A + 1
end
TABLE[i] = A
end
end
until TABLE[N] == 0
end
function GenerateTiles()
for i = 1,16*12 do
local X = (i%16-1)*25 + 25
local Y = math.floor((i-1)/16)*25
local Tile = script.Tile:Clone()
Tile.Parent = script.Parent.Tiles
Tile.Name = i
Tile.Position = UDim2.new(0,X,0,Y)
Tile.Visible = true
end
CANSTART = true
end
function Expand(N)
if TABLE[N - 17] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N - 17)
if TABLE[N - 17] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N - 16] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N - 16)
if TABLE[N - 16] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N - 15] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N - 15)
if TABLE[N - 15] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N - 1] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N - 1)
if TABLE[N - 1] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N + 1] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N + 1)
if TABLE[N + 1] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N + 15] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N + 15)
if TABLE[N + 15] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N + 16] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N + 16)
if TABLE[N + 16] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
if TABLE[N + 17] ~= nil then
local Obj = script.Parent.Tiles:FindFirstChild(N + 17)
if TABLE[N + 17] < 9 and Obj then
if Obj.BackgroundColor3 == Color3.fromRGB(125,125,125) then
Flip(Obj)
end
end
end
end
function NewGame()
Clear()
GenerateTiles()
for i = 1,#script.Parent.Tiles:GetChildren() do
script.Parent.Tiles:GetChildren()[i].MouseButton1Click:Connect(function()
Steps = Steps + 1
Flip(script.Parent.Tiles:GetChildren()[i])
end)
script.Parent.Tiles:GetChildren()[i].MouseButton2Click:Connect(function()
Flag(script.Parent.Tiles:GetChildren()[i])
end)
end
end
function Flag(Tile)
if CANSTART then
if Tile.Text =="!" then
Tile.Text = ""
else
if Tile.Text == "" then
Tile.Text = "!"
Tile.TextColor3 = Color3.fromRGB(255,0,0)
end
end
end
end
function GameOver()
if CANSTART == true then
CANSTART = false
for i = 1,#TABLE do
if script.Parent.Tiles:FindFirstChild(i) and TABLE[i] == 9 then
script.Parent.Tiles:FindFirstChild(i).BackgroundColor3 = Color3.fromRGB(255,0,0)
end
end
end
end
function Flip(Tile)
if CANSTART == true and Tile ~= nil then
if Steps == 1 then
Generate(tonumber(Tile.Name))
end
if TABLE[tonumber(Tile.Name)] == 0 then
Expand(tonumber(Tile.Name))
Tile.BackgroundColor3 = Color3.fromRGB(200,200,200)
end
if TABLE[tonumber(Tile.Name)] == 9 then
GameOver()
end
if TABLE[tonumber(Tile.Name)] ~= 9 and TABLE[tonumber(Tile.Name)] ~= 0 then
Tile.Text = TABLE[tonumber(Tile.Name)]
Tile.TextColor3 = COLORTABLE[TABLE[tonumber(Tile.Name)]]
Tile.BackgroundColor3 = Color3.fromRGB(200,200,200)
Tile.AutoButtonColor = false
end
else
if Tile == nil then
print("TileNIL")
end
end
end
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
NewGame()
Steps = 0
end
end)
I know the script is kinda terrible.