local function addClickDetectors() getCurrentRowIndex(currentRowIndex) getCurrentTileIndex(currentTileIndex) for i,v in pairs(tileTableTable) do if i <= currentRowIndex + 2 and i >= currentRowIndex - 2 then for x,z in pairs(v) do if x <= currentTileIndex + 2 and x >= currentTileIndex - 2 then getClickDetector(clickDetectorClone) clickDetectorClone.Parent = z end end end end for i,v in pairs(tileGrid.Rows:GetChildren()) do if i <= currentRowIndex + 2 and i >= currentRowIndex - 2 then for x,z in pairs(v:GetChildren()) do print(z) if x <= currentTileIndex + 2 and x >= currentTileIndex - 2 and z.Value.Value == 250 then z.BrickColor = BrickColor.new("Fossil") end end end end end
The first for loop adds click detectors to the tiles in a two tile radius around the player, the second one changes the color of the tiles to give an easy visual indicator for which tiles are clickable. Currently, you can click on the tiles for a second before they actually light up. What might a good method be for causing these two events to happen simultaneously? Also the two for loops are iterating over two different tables, so I can't just combine them into one. Thank
Maybe you can use a spawn(function(), it allows the loop to run while the rest of the code is also running, use the spawn function on the first loop
spawn(function() for i = 1, 10 do print(i) end end) for i = 1, 10 do print(1, 10) end
Spawn Function This creates a thread and it runs the code separately on it.