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

How to randomize the values in a table?

Asked by 9 years ago

[Fixed it by myself]

Tried this, works sometimes, sometimes fails..

local Difficulties = {"Hard","Easy","Normal"}
table.sort(Difficulties, function(a,b)
return math.random() > 0.5
end)
print(table.concat(Difficulties, ' '))

Error: 13:17:48.509 - Workspace.Script:5: invalid value (nil) at index 1 in table for 'concat'

1 answer

Log in to vote
1
Answered by 9 years ago

Why not grab a random value from the table?

Difficulties[math.random(1, #Difficulties)]

Also, see http://wiki.roblox.com/index.php?title=Random_numbers#math.randomseed.

Ad

Answer this question