-1

I have this script on 2 npcs but both choose the same random number (7) how do I make the Npcs choose their own number? I did try with self.math.random and it gave an error so what would the solution be? will I have to create different variables for each npc related to the random function?

function Behavior:Awake()
    math.randomseed (os.time())
self.destino = math.random( 1, 7 )

In the engine I work with it says to put self. for independence...

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64

1 Answers1

3

The fact that you call math.randomseed inside a function suggests to me that you're calling it every time you want a random number. The purpose of math.randomseed is to initialize the RNG, which means you're initializing the RNG multiple times, hence the repetition. Usually, you need to call math.randomseed exactly once in the entire program.

it says to put self. for independence...

That's not a great explanation of how self works. self is a function parameter that gets automatically declared when you declare a function with colon notation.

luther
  • 5,195
  • 1
  • 14
  • 24