Array items being removed but not added again

I have NPC’s that i can assign different things like builder. I am using the system below to assign a labourer to builder. But sometimes it seems that they just disappear from the list and I understand that there’s something wrong with what I’ve done but I don’t quite understand why(i’m still new to this).

Thus the error is that the items seems to be removed from their arrays without being added again. If i spawn 10 labourers and switch them between builder and labourer I pretty quickly end up only having 1 labourerr/builder left.

edit1: it seems that by the time it reached add the random integer in range has a value and by the time it reaches SetIsBuilder the random integer in range has another value. That could be the problem.

How would i go about doing this? Tried adding the set variable right after the Random Integer in Range just like you did there but it just made it not work at all.

Wow i’m dumb, didn’t connect the nodes correctly, the add isn’t connected. It works like intended. Thank you for quick answer! :slight_smile:

it seems that by the time it reached
add the random integer in range has a
value and by the time it reaches
SetIsBuilder the random integer in
range has another value. That could be
the problem.

And you are correct here, nicely spotted. You’re accessing the Get node twice, and it queries for a Random Integer twice - giving you 2 random results. Adding and removing 2 (different) random array elements in the process.

The solution here is to store the result of the random operation and then use it: