Math.random is not randomizing?

Hello, developers. I thought I would never make a thread about this, but here I am.

I am making a game and cash has a 2/3 chance of disappearing before the game starts. However, the math.random number is always the same.

What happens is all the money disappears or none of it gets destroyed.

I have tried putting the math.random inside of a function and outside of it too. I’ve even tried math.randomseed, but nothing works

Code:

function Check()
	math.randomseed(os.time())
	local Number = math.random(1, 3)
	if Number == 1 or Number == 2 then
		script.Parent.Parent:Destroy()
	end
end

function onTrigger(Player)
	local N =  math.random(50, 100)
	script.Parent.MaxActivationDistance = 0
	script.Parent.Parent.Transparency = 1
	Player.leaderstats.Money.Value += N
	game:GetService("ReplicatedStorage").SendNotification:FireClient(Player, "Money Found", "You found $"..N, 5)
	task.wait(180)
	script.Parent.MaxActivationDistance = 8
	script.Parent.Parent.Transparency = 0
end

Check()
script.Parent.Triggered:Connect(onTrigger)

I am really confused. :confused:

I am still stuck on this problem!

Remove the line where the random seed is set.

Because of the low resolution of os.time(), all of the money piles have their random seeds set to the same value, which in turn causes all of their random calls to return the same number, and so they all behave identically. By not resetting the seed, each call will get the next number in the sequence rather than the first.

1 Like