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!
randomized Tile path minigame -
What is the issue? Include screenshots / videos if possible!
The path isn’t turning blue and not printing there isn’t one -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried studying this one code but uh confused me so i did my own with some of their code in there
You can try this in studio
local pathwd = 10
local height = 1
local position = height / 2
local pathstack = {}
table.insert(pathstack, { ZCell = 0, Xcell = 0 })
local row = 10
local collum = 6
local ran = Random.new()
local pathss = {}
local directions = {
Vector3.new(1, 0, 0), -- Right
Vector3.new(0, 0, 1), -- Forward
Vector3.new(-1, 0, 0), -- Left
Vector3.new(0, 0, -1), -- Backward
Vector3.new(1, 0, 1), -- Top-Right Diagonal
Vector3.new(-1, 0, 1), -- Top-Left Diagonal
Vector3.new(1, 0, -1), -- Bottom-Right Diagonal
Vector3.new(-1, 0, -1) -- Bottom-Left Diagonal
}
local function createpart(x, y, z, rx, ry, rz)
local part = Instance.new('Part')
part.Parent = game.Workspace
part.Size = Vector3.new(x, y, z)
part.Position = Vector3.new(rx, ry, rz)
part.Anchored = true
return part
end
for z = 0, row - 1 do
maze[z] = {}
for x = 0, collum - 1 do
maze[z][x] = { }
end
end
local function tiles()
for z = 0, row - 1 do
for x = 0, collum - 1 do
local tilex = x * 17
local tilez = z * 17
local part = createpart(pathwd, height, pathwd, tilex, position, tilez)
if part then
part.Name = string.format("%d,%d", z, x)
part.Parent = game.Workspace.Folder
maze[z][x].Tile = part
local valuesx = Instance.new("NumberValue",part)
valuesx.Name = "X"
valuesx.Value = x
local valuesz = Instance.new("NumberValue",part)
valuesz.Name = "Z"
valuesz.Value = z
end
end
end
end
local function getneighors(z, x)
local neighbors = {}
for _, direction in ipairs(directions) do
if z and x then
local newZ = z + direction.Z
local newX = x + direction.X
if newZ >= 0 and newZ < row and newX >= 0 and newX < collum then
if maze[newZ][newX] and not maze[newZ][newX].Visited then
table.insert(neighbors, maze[newZ][newX])
end
end
end
end
return neighbors
end
local function reconstructpart(endn,previous)
local path = {endn}
repeat
local cn = path[#path]
local previousnode = previous[cn]
if previous then
print(previous)
table.insert(path,previous)
end
until not previousnode
return path
end
local function path(endn,startn)
for z = 0, row - 1 do
for x = 0, collum - 1 do
maze[z][x].Tile.BrickColor = BrickColor.Black()
end
end
repeat
task.wait()
local previous = {}
local stackcell = pathstack[#pathstack]
local x = stackcell.Xcell
local z = stackcell.ZCell
repeat
task.wait()
local neighbors = getneighors(z, x)
local randomneighbor = ran:NextInteger(1, #neighbors)
local nextcell = neighbors[randomneighbor]
if nextcell and #neighbors > 0 then
if nextcell then
previous[nextcell] = stackcell
nextcell.Visited = true
nextcell.Tile.BrickColor = BrickColor.Red()
table.insert(pathstack, { ZCell = game.Workspace.Folder:FindFirstChild(nextcell.Tile.Name).Z.Value, Xcell = game.Workspace.Folder:FindFirstChild(nextcell.Tile.Name).X.Value })
if nextcell.Tile == endn then
print(previous)
return reconstructpart(endn,previous)
end
end
else
table.remove(pathstack,#pathstack)
end
until
not nextcell
until
#pathstack == 0
end
tiles()
local startnode = game.Workspace.Folder:FindFirstChild(string.format("%d,%d", 0, math.random(0, collum - 1)))
local endnode = game.Workspace.Folder:FindFirstChild(string.format("%d,%d", row - 1, math.random(0, collum - 1)))
print("Start Node:", startnode)
print("End Node:", endnode)
local pathway = path(endnode,startnode)
if pathway then
for i,v in pairs(pathway) do
if v then
if v ~= endnode and v ~= startnode and v.Tile then
print("yes")
v.Tile = BrickColor.Blue()
v.Tile.CanCollide = false
end
end
end
else
print("no path")
end
Sorry if i reply late since am going through the hurricane.