#The reasoning
There is no issue, the only problem is the human mind. Why? Because humans have the power to see patterns in everything[^1]. Something that machines don't have. So even though something is as random as possible it may not seem random at all because we spot a pattern. That's why making something random is so difficult. So roblox has something called a randomseed which is a seed that the pseudo-random generator refers to. Kind of like how minecraft you need a seed to load a certain maps. Equal seeds create equal outcomes.
#math.randomseed
Math.random has it's own default seed. Whenever you run it you'll always get the same sequence of numbers.
print(math.random(100))
89
When you restart the game it'll still print
89
How do you get this to change? You change the randomseed.
math.randomseed(2)
print(math.random(100))
1
But we return to the original problem, it doesn't stop printing 1 the first time!
We need to change the random seed to a never changing number, what's a number that never stops... Time! Time never stops. But how do we get time? tick() or os.time. We'll use tick() because it's easier. tick() is the local or UNIX time. Basically the time on your computer right now. tick() returns the number of seconds since the epoch or 1 January 1970, 00:00:00. So we can make the random seed that value.
#Final Product
Please note that math.randomseed does NOT have to be placed at the beginning of the script.
function onTouched()
math.randomseed(tick())
local partchoice = math.random(1,3)
if partchoice == 1 then
game.Workspace.Part1:Destroy()
script.Parent:Destroy()
end
if partchoice == 2 then
game.Workspace.Part2:Destroy()
script.Parent:Destroy()
end
if partchoice == 3 then
game.Workspace.Part2:Destroy()
script.Parent:Destroy()
end
end
script.Parent.Touched:connect (onTouched)
Hope it helps!
[^1]: What is Random? by VSause
1 comment
Have you checked that it actually comes up with a different random number?