Destroying a component based on random integer in range (like dice)

Hi all,

I’m having trouble figuring out what is wrong with this section of my script. I have it set up so that there are two random integer ranges from 1-6 (like dice) added up. If the total is >= 7 then the component should be destroyed.

For debugging purposes I have it printing the end result integer.

Now, sometimes the component gets destroyed, but this event doesn’t seem to correlate with the >= boolean i have put into place.

Sometimes it destroys when it prints 4, sometimes at 6, sometimes it doesn’t destroy at 9, sometimes it does destroy at 9, and so on. I really can’t figure out what’s going on. It’s approximately 50/50 whether it gets destroyed or not, but it doesn’t reliably correlate to my random integer ranges’ outputs.

Appreciate the help

Thank you very much, that solved the problem, and incidentally was something I had considered doing but wasn’t sure, so a good reminder to follow my intuitions. All the best.

the way you currently have your script setup it will get random numbers twice. basically when it does the >= it will get one set of numbers, then when you print string it will run the randoms again and get a different set. to combat this try saving the result of the add to a variable, then use the variable for the >= and the print. by using a variable the random will only be run once and the result saved in a way that wont change.