Function is supposed to be random but is not?

so i made a function that spawns an npc and rolls a random weapon for it, but i noticed that every time all npcs had the same weapon and they all spawned in the same location. so i added a math random to the function for debugging purposes, and for some reason the number is always the same? why is this happening? ive never had this happen to me before


image

instead of
math.random(x,y)
try

local generator = Random.new()
local randomNum = generator:NextNumber(x, y)
1 Like

you will need to change the seed because you’re restarting the variable each time so add this before local randomnum = math.random(1,599) :

math.randomseed(os.time())
local randomnum = math.random(1,599)
1 Like

added it on top of the function and i am still getting the same values every time
image

Try what jamey said i’m not entirely sure about this issue

can u show the “roll” function ? u call it for gunequipped’s value

ive been using it for years and its never failed me so i doubt its the issue but here u go
image

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