Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to select a random name in a table?

Asked by 4 years ago
local crime = {"Robber","Killer","None","Fighting","Spawnkilling","Sneaky","Hacking"}

local mathr = math.random(1,7)
if mathr == #crime then
    print (math.random(#crime,7))
end

Nothing outputs. Help?

1 answer

Log in to vote
0
Answered by
gloveshun 119
4 years ago
Edited 4 years ago
local crime = {"Robber","Killer","None","Fighting","Spawnkilling","Sneaky","Hacking"}

local number = math.random(1,#crime)


local chosen = crime[number]
print(chosen)

Hope this helped!

0
You can also write >| local chosen = crime[math.random(1,#crime)] Ziffixture 6913 — 4y
0
Yes gloveshun 119 — 4y
0
Thanks it works. antoniorigo4 117 — 4y
0
Nope gloveshun 119 — 4y
Ad

Answer this question