You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hello!! I need some help on a game mechanic i want to add. Specifically, when you click on an empty tile in Minesweeper, it’ll reveal all the other tiles around it! -
What is the issue? Include screenshots / videos if possible!
Cant find a solution to my problem, as stated above. -
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
Looked everywhere for a solution, haven’t found one yet. Checked dev forums and couldn’t find much either, so i decided to make my own post, this one!
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
As usual, here is my script.
(ModuleScript, btw)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local IconsFolder = ReplicatedStorage:WaitForChild("Icons")
local SoundsFolder = ReplicatedStorage:WaitForChild("Sounds")
local Tile = {
Colors = {
One = Color3.fromRGB(0, 0, 255),
Two = Color3.fromRGB(0, 128, 0),
Three = Color3.fromRGB(255, 0, 0),
Four = Color3.fromRGB(0, 0, 128),
Five = Color3.fromRGB(128, 0, 0),
Six = Color3.fromRGB(0, 128, 128),
Seven = Color3.fromRGB(0, 0, 0),
Eight = Color3.fromRGB(128, 128, 128),
Nine = Color3.fromRGB(85, 0, 127),
}
}
local HitboxSize = Vector3.new(8,4,8) -- Hitbox size for tile detection
local overlapParams = OverlapParams.new()
local MineCount = 0
local function MineTriggered(part, Text)
part.CanTouch = false
part.CanQuery = false
part.ClickDetector.MaxActivationDistance = 0
for i,v in pairs(part.SurfaceGui:GetChildren()) do
if v:IsA("ImageLabel") and v.Name == "FlagIcon" then
v:Destroy()
end
end
local newIcon = IconsFolder.Mine:Clone()
newIcon.Parent = part.SurfaceGui
task.wait(1)
local NewSound = SoundsFolder.Explosion:Clone()
NewSound.Parent = part
NewSound:Play()
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = workspace
Debris:AddItem(NewSound, NewSound.TimeLength)
Debris:AddItem(part.ClickDetector, 3)
end
local function Colourise(part, Text)
-- Temporary, i'll find a better solution for this later.
if MineCount == 1 then
Text.TextColor3 = Tile.Colors.One
elseif MineCount == 2 then
Text.TextColor3 = Tile.Colors.Two
elseif MineCount == 3 then
Text.TextColor3 = Tile.Colors.Three
elseif MineCount == 4 then
Text.TextColor3 = Tile.Colors.Four
elseif MineCount == 5 then
Text.TextColor3 = Tile.Colors.Five
elseif MineCount == 6 then
Text.TextColor3 = Tile.Colors.Six
elseif MineCount == 7 then
Text.TextColor3 = Tile.Colors.Seven
elseif MineCount == 8 then
Text.TextColor3 = Tile.Colors.Eight
elseif MineCount == 9 then
Text.TextColor3 = Tile.Colors.Nine
end
end
function Tile.RevealTile(part, Text)
task.wait()
if part:GetAttribute("Mine", true) then
MineTriggered(part, Text)
return
end
local hitContents = workspace:GetPartBoundsInBox(part.CFrame,HitboxSize, overlapParams)
for i,v in pairs(hitContents) do -- search for tiles in a 3x3 area
if not v then return end
if v.Name == "Mine" then
MineCount += 1
elseif v.Name == "Tile" and MineCount <= 0 then
print("chainreact")
local v_Text = v.SurfaceGui.TextLabel
v.CanTouch = false
v.CanQuery = false
end
end
--[[if MineCount == 0 then
for i,v in pairs(part.SurfaceGui:GetChildren()) do
if v:IsA("TextLabel") then
print("chainreact")
Tile.RevealTile(v, Text)
end
end
end]]
part.CanTouch = false
part.CanQuery = false
if MineCount > 0 then
Text.Text = MineCount
Colourise(part, Text)
end
MineCount = 0
--print("there is "..MineCount.." Mine(s) around this area.")
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Thanks for reading! Hope you can help with my problem! ![]()
