Choosing random virus game

I am making a virus game and in this script it is supposed to change the ‘Chosen Virus’ variable. Variables have already been defined in other script btw

local Variables = require(script.Parent.Variables)
Variables.ChosenVirus = Random(Variables.Virus1, Variables.Virus2, Variables.Virus3, Variables.Virus4, Variables.Virus5)
print(Variables.ChosenVirus)

Its not printing the chosen virus… Why?

ps, game will not be released until pandemic is over. This could cause stress to people due to the fact that in this game there is a virus.

1 Like

Is Random a function you’ve already defined?

There seems to be some code lacking here, so it’s hard to determine the problem.

What do you mean, do I have to define it?

1 Like

Are you trying to use the Random object to randomize a selection? You have to use random numbers instead because Random does not specifically do that.

Example:

local rand = Random.new()
local randomNum = rand:NextInteger(1, 4)

I have just done

Random(test1, test2)

before and it worked…

I am also a rookie scripter, can you tell me how to make it so it chooses one of those vars?

Are you talking about your own Random function or the object? There is clearly nowhere in the page for the Random object that says you can do Random(object, object)

Wait here, I will make a script which is easier to understand…

So it will set the ‘Chosen Virus’ to one of the values of the following vars then print the value of the chosen var.

local Variables = require(script.Parent.Variables)

Variables.ChosenVirus = Random(Variables.Virus1.Value, Variables.Virus2.Value, Variables.Virus3.Value, Variables.Virus4.Value, Variables.Virus5.Value)

print(Variables.ChosenVirus)

Nothing changed? I’m saying use random numbers to get an index for a table that which value you get from the random index is the random virus.

Example:

local t = {“example”, “just an example”, “this is an example”}
local r = Random.new() -- seed optional
local randomValue = t[r:NextInteger(1, #t)]
4 Likes