Hey i want to make a table that when called on picks 1 random thing out of all the things in the table and prints it.
So far iv tried watching youtube videos and looking at other posts without success. Iv even asked my friend and they dont know.
Technically you wouldn’t be writing the entire script if you did what i said since all your doing is printing it not coding it to actually be part of anything. Honestly though i dont really know if that counts so if it does then explain each service and etc since i know like 2 services.
local map = {cafe, work, home}
local random = math.random(1,3)
if random = 1 then
load:FireServer(cafe)
elseif random = 2 then
load:FireServer(work)
else
load:FireServer(home)
end
Here you go, added some notes so you could understand the code better. :)
local table = {"Apple", "Orange", "Banana"} --Table of items.
local function selectRandom() --Creates function.
local rand = math.random(1,#table) --creates a variable that selects a number between 1 and how many items you have in your table. In this case, there's 3 items.
if rand == 1 then --if the random number is 1, then it prints the first item in the table.
print(table[1])
elseif rand == 2 then --if the number is 2, then it prints the second item in the table.
print(table[2])
elseif rand == 3 then --if the number is 3, then it prints the third item in the table.
print(table[3])
end
end
selectRandom() --calls upon the function, therefore activating it.