How can I change my iterating loop to reduce lag?

I am trying to implement a feature which changes the color of every ‘hexagon’ that a player touches, to that player’s matching TeamColor. The code is working however it causes a lot of lag, most likely due to it iterating over all 5000 hexagons every time either one of the events are fired (they are fired when the player clicks the play button). I have tried referencing the player in different ways so that it doesn’t have to iterate every time the event is fired, but I don’t know any other ways I could fix this.

1 Like

Triggering a function for each hexagon is a bit much since in the RAM, it takes a slot for each function it needs to keeps tab on, and since you have 5000 of them, it’s bound to lag.

why not link the touched function with what is supposed to touch the hexagon instead… I’m sure there’re less instance of it

1 Like

I realised that this code wasn’t actually causing any lag, it was another script, but thanks for help anyways.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.