Hey there!
For context
I’m creating a placement system to build structures using a custom position system
The easiest way of imagining it is basically just a coordinate plane. You start building at (0, 0), expand outwards in any direction from that position (0, 1), and more grids become available as you start building from that. Anyways, that’s not important.
The main I’m running into is enabling each available grid
I’ve tagged each possible grid where the player can place an item, and I’m then putting each element into an array, that will be compared against each element to determine if the positions are the same
This is so that multiple grids are not overlapping each other, and so that the player can place exactly 1 item per grid
Below is the main script:
function isValid()
local check = {}
itemsToBe = {}
for _, v in pairs(cs:GetTagged("comparingBoundaries")) do
table.insert(itemsToBe, v)
end
for _, v in pairs(itemsToBe) do
local xV = v:FindFirstChild("xCoord")
local yV = v:FindFirstChild("yCoord")
for _, j in pairs(itemsToBe) do
if v and j and v ~= j then
local xJ = j:FindFirstChild("xCoord")
local yJ = j:FindFirstChild("yCoord")
if xV.Value == xJ.Value and yV.Value == yJ.Value then
determineIt(v, j, itemsToBe)
end
end
end
end
end
In the below screenshot, you can see that this is sometimes inaccurate and that the available grids overlap parts that are already existing
The odd part is that the inconsistencies vary. When you place down the item and pick it up again, the available grids shift. Sometimes it’s accurate, sometimes it’s not. In this case, it was not accurate
The main issue might be the way I’m determining which grid gets to show and which one doesn’t once they overlap, as I’m just using a random number generator
function determineIt(x, y, array)
local xyz = math.random(1, 2)
if x.Name == "main" then
if (table.find(array, y)) then
table.remove(array, table.find(array, y))
end
elseif y.Name == "main" then
if (table.find(array, x)) then
table.remove(array, table.find(array, x))
end
else
if xyz == 1 then
if (table.find(array, y)) then
table.remove(array, table.find(array, y))
end
else
if (table.find(array, x)) then
table.remove(array, table.find(array, x))
end
end
end
end
Wow, that was a lot, but hopefully I was detailed enough to explain my issue
Any help/suggestions are appreciated greatly!