Grabbing certain tiles in order using Touched event

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I have a number of tiles that I want to keep stored in a dictionary with their positions per tile, and I thought the method would have been to CFrame from the starter tile to the end tile the distance between the two and grab the tiles in between. However, when I went through the ordering of all the tiles grabbed by the Touched event, I noticed that they are not in order and I assume that’s because I CFramed it instantly to the magnitude, so it ended up touching all of those tiles at the same time. I need those tiles to be ordered properly, and I can’t think of a way to do it unless I either lerp, tween, or manually CFrame them. Lerping takes a lot of resources it looks like (and isn’t fast enough), and tweening seems slow because I need the tiles grabbed ASAP for gameplay smoothness. Manual CFrame looks to be the best option, but I’m not very sure how I would do that, that is, how I would make it (a kind of ray that detects all the tiles) stretch enough to the end tile, so to the direction of the end tile and just enough that it does not go beyond it and touch another tile. CFrame is still a hazy spot for me, so any ideas are appreciated.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Just looked through lerping, tweening, and writing down notes on how I would manual CFrame it. Can’t quite wrap my head around it.


They are not in order because they are

The dictionary part of a table is unordered. If you need order then store the positions in the array part.

What do you mean? The CFrame of it is set first, then the Touched event is connected, and finally the part is put into Workspace for it to work. Hence my theory, but I don’t understand what you mean.

You say you have them in a dictionary. I am telling you that there is no inherent order for a table’s dictionary part.

for key in pairs({ a = 1, b = 2, c = 3 }) do

The order is unlikely to be a, then b, then c. It could go in any order

That’s strange. How are you imagining that I put in my values? Or are you talking about the array of Touched parts?

Edit: I have a for-loop iterating through the GetTouchingParts() list and grabbing everything relevant touched that is not repeated. So, if anything isn’t ordered, it’d be that list, and I know that already. I’m looking for a new method.

Yea, no, still the same issue. I tried putting it into an array with just referring to the hit tiles, not in a dictionary, and the same problem pursues. I have no idea why the dictionary would be an issue unless in Lua even if you arbitrarily put in a way it still won’t necessarily iterate through the same way. Which, I wouldn’t have known, but that does not seem to be the problem.

Edit: I even made the size of the ray extended after connecting the Touched event to it and when it’s pointed in the correct direction. Still, same issue. I’m really certain that it isn’t the way the dictionary was implemented, how the values were placed in it, instead, the ray touches all parts simultaneously and thus would have no order.

Edit2: And yea, I’m not used to my dictionaries being iterated in a random order even when I write to them in an arbitrary pattern. Can I get some confirmation on that? That’s so weird I actually don’t think that’s true.