Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Good method for causing two different for loops to fire simultaneously?

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

3 comments

0

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

0

This works thank you

0

Can you accept my answer? Just to get the question marked as "answered"

2 answers

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.