I’m currently trying to use parts that surround the tile as a way to position the clone of the tile properly. All I need to figure out is how to clone the tile as many times as necessary to fill in the every part around the tile.
Heres a snippet of code that im trying to use to achieve what i said above (i know this doesnt work ive just made something to go off of):
local replicatedStorage = game:GetService("ReplicatedStorage")
local tileEmpty : Model = replicatedStorage:WaitForChild("tileEmpty")
local tile = script.Parent.Parent
local freeSpaces = tile.Spaces
local function replaceSpaces()
for i = 1, #freeSpaces:GetChildren() do
local tileClone = tile:Clone()
tileClone.Parent = workspace.Tiles.Full
tileClone:PivotTo(freeSpaces:FindFirstChild("Space"))
end
end
and screenshots of how my things are setup in the explorer:
Your code probably isn’t working because it’s cloning the tile but placing every clone at the same position. The PivotTo function is only moving each clone to the first space it finds, instead of each individual space. You need to loop through each space and position each clone accordingly. BUT if this is not the code you are using and you want help with this code I’m not sure on that but you could make some advanced tile placing logic and the other logic that needs to be implemented.
Not sure how your game works, however from a simple viewpoint, if creating a fixed size minesweeper game, one could start off using a naming convention, something simple like numbers (1:1 for top left [1st row, 1st column], x:y for bottom right [xth row, yth column]) get the surrounding 8 (or less) pieces of the clicked area by performing -1 and +1 calculations on the clicked piece’s name, and reveal their nature. Hopefully this helps.
Leaving this crossed out in case anyone does want to create such a game, however I now understand what you’re trying to achieve.
Finds the first Space under freeSpaces, it will be the same each time (in your case, the middle). Furthermore, there is no specified CFrame for it to pivot to, Here is an alternate loop that should work:
local replicatedStorage = game:GetService("ReplicatedStorage")
local tileEmpty : Model = replicatedStorage:WaitForChild("tileEmpty")
local tile = script.Parent.Parent
local freeSpaces = tile.Spaces
local function replaceSpaces(CurrentCFrame)
for _, Space in freeSpaces:GetChildren() do
if Space.CFrame == CurrentCFrame then
Space:Destroy()
continue
end
local tileClone = tile:Clone()
tileClone.Parent = workspace.Tiles.Full
tileClone:PivotTo(Space.CFrame)
Space:Destroy()
-- make new spaces
end
end