Making random orders for players

Hello,

So right now i’m trying to make orders for my game so players can complete them for cash.
But I need some help to make it randomized. So the the names will be in the gui and the gui will be there only if there is an order to complete.

So I think that the Gui needs to be created when there is an random order right?

So far I only have this;

local names = {"Monica, Joey, Sarah, Michel, Michael, James, Adam"}

local companyNAMES = {"Electro Shop, Cablebar, Airedable, Tvus, Videosify, Tellyware, Onaired, Remixus, Technomax, Elevatelly, Envideos, Inc.ia, Cotv, Coremix, Edaired, Unitelly "}


If someone can help me making this I really would appreciate that! Thanks a lot!

1 Like

You could do.

local randomtask = math.random(1, putmaxnumberhere)

Then you could do the task by saying companyNAMES[randomtask]

That doesn’t works if cause if I put

that then it doesn’t do anything.

What you could do is:

local List = {1, 2, 3, 4, 5, 6}

local TempList = {}
for i = 1, #List do
   table.insert(TempList, List(math.random(1, #List))
end

List = TempList
Templist = {}

What this should do is create a new empty list (TempList), put the items from the list (List) in random order in that list (TempList), and then set the list (List) to the newly created list (TempList). And boom, random order.

Not sure if this works, let me know!

You could get the table’s variable by doing:

tableName[variableNumber]

For example:

names[1] -- Monica

So you just need to randomize the variableNumber!

To get the total length of table, you use:

#tableName

For example:

#names -- 7

You will randomize it with

math.random(minNumber, maxNumber)

So:

names[math.random(1, #names)] -- any possible variable inside table names

You just need to do

print(names[math.random(1, #names)])

to get the random names…

Not sure if this is what you need, but I hope I helped!

This works just fine tho but it needs to print only ‘1’ name…

The script @Xapelize made is great for printing one random item from a list.

Because you aren’t making it do anything. companyNAMES[randomtask] will pick a random line of the table.
If you want it to do something, then do:

local randomtask = math.random(#companyNAMES) -- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
print(companyNAMES[randomtask])

It will print the random task.
If you want to learn more about tables, go to:

Samething here if I do that it is printing all of the names how can I make that not happen?

local companyNAMES = {"Electro Shop, Cablebar, Airedable, Tvus, Videosify, Tellyware, Onaired, Remixus, Technomax, Elevatelly, Envideos, Inc.ia, Cotv, Coremix, Edaired, Unitelly "}

Because you only have one line in your table. Which is all of them.
You need to put quotations around each one.

Ex:

{"test1"," test2"}
1 Like

have no idea

local names = {"Monica", "Joey", "Sarah", "Michel", "Michael", "James", "Adam"}

local companyNAMES = {"Electro Shop", "Cablebar", "Airedable", "Tvus", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly"}

for strings, name in pairs(names) do
	for strings, company in pairs(companyNAMES) do
		local Len = tonumber(table.getn(names))
		local Len2 = tonumber(table.getn(companyNAMES))
		
		wait()

		local NewRand = math.random(1, Len)
		local companyRand = math.random(1, Len2)
		
		print(names[NewRand])
		print(companyNAMES[companyRand])
	end
end

haven’t tested it out yet so I have no idea if it works or not

if you’re wanting the script not to loop, remove the for loop parts

@CodedJack I’ve came this far this time but cause the text won’t change to the given names in the metatable. But it says an number anyway to get the random name which is in the meta table?

Send the script you have so far.

local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam"}

local companyNAMES = {"ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly" }
local ReplicatedStorage = game.ReplicatedStorage.TvOrderRMDs


local tvOrdersRMD = {"OldTv", "Salora 58UA330"}


local randomtask = math.random(#companyNAMES) -- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
local randomtask2 = math.random(#names)


local guiPlaces = game.StarterGui.ComputerMenu.Orders.Background1.OrderPlaces.Value

if guiPlaces == 0 then
	local ORDER = Instance.new("TextButton")
	ORDER.Parent = game.StarterGui.ComputerMenu.Orders.Background1
	ORDER.Size = UDim2.new(0.25, 0, 0.278, 0)
	ORDER.Position = UDim2.new(0.122, 0, 0.146, 0)
	ORDER.Name = "Order1"
	ORDER.BackgroundColor3 = Color3.fromHSV(0.54425, 0.886275, 1)
	ORDER.Text = #names
	local Name = Instance.new("TextLabel")
	Name.Name = "Name"
	
	
	local CircleGui = Instance.new("UICorner")
	CircleGui.Parent = ORDER
	
	
	
	
	guiPlaces = guiPlaces + 1
	
end



@RichardPRoosevelt There you go

Putting a hashtag before something gives the number of it.
So, try this:

`	ORDER.Text = names`

However, you are setting the name of the text to a table. Which is not going to work.

I assume you are trying to have a random name right?

Thats right. So it will be randomly given a name is that possible?

I modified your script to make this work.


local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam"}

local companyNAMES = {"ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly" }
local ReplicatedStorage = game.ReplicatedStorage.TvOrderRMDs


local tvOrdersRMD = {"OldTv", "Salora 58UA330"}


local randomtask = names[math.random(#names)] -- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
local randomtask2 = math.random(#companyNAMES)


local guiPlaces = game.StarterGui.ComputerMenu.Orders.Background1.OrderPlaces.Value

if guiPlaces == 0 then
	local ORDER = Instance.new("TextButton")
	ORDER.Parent = game.StarterGui.ComputerMenu.Orders.Background1
	ORDER.Size = UDim2.new(0.25, 0, 0.278, 0)
	ORDER.Position = UDim2.new(0.122, 0, 0.146, 0)
	ORDER.Name = "Order1"
	ORDER.BackgroundColor3 = Color3.fromHSV(0.54425, 0.886275, 1)
	ORDER.Text = randomtask
	local Name = Instance.new("TextLabel")
	Name.Name = "Name"
	
	
	local CircleGui = Instance.new("UICorner")
	CircleGui.Parent = ORDER
	
	
	
	
	guiPlaces = guiPlaces + 1
	
end


First:
This variable was only getting a number.

Changed to:

local randomtask = names[math.random(#names)]

The new variable is picking a random name by referencing table[number].


Second:

Referencing a table is not going to work. So, we can change this to the variable I just edited (randomtask).

Changed to:

ORDER.Text = randomtask

This is putting the Text as the random name picked in the randomtask variable.


If you want to get the text of the random company name, you can do the same thing. Change the randomtask2 variable to work, and put the text as the randomtask2 variable.