local Parent = script.Parent Letters1 = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} Numbers1 = {"1","2","3","4","5","6","7","8","9","0"} Letters2 = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} Numbers2 = {"1","2","3","4","5","6","7","8","9","0"} Numbers3 = {"1","2","3","4","5","6","7","8","9","0"} game.Players.PlayerAdded:connect(function(Player) local Figure1 = Letters1[math.random(#Letters1)]; local Figure2 = Letters1[math.random(#Numbers1)]; local Figure3 = Letters1[math.random(#Letters2)]; local Figure4 = Letters1[math.random(#Numbers2)]; local Figure5 = Letters1[math.random(#Numbers3)]; wait(15) Parent.Text = "Current Subject "+Figure1+Figure2+"-"+Figure3+Figure4+Figure5 print("Working") end)
Script logic : when player joins, script generates a random 2 fig - 3 fig order. Why isn't it working?
In Lua, the concatenation operation is ..
and not +
. Also, this script could be a lot more efficient.
Also, to get a random value from an array, it is array[math.random(1,#array)]
. You also, don't need a separate table for each figure, and for numbers, just use math.random. Don't forget to use randomseed, though. Also, you have to filter the text, as randomly generated text must be filtered so that it is appropriate for Roblox.
More about filtering random words.
Anyway, here is your script.
math.randomseed(tick()) local Letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} game.Players.PlayerAdded:connect(function(Player) local text = "Camera Subject " for i = 1,5 do text = text..((((i/2 == math.floor(i/2)) and math.random(0,9)) or Letters[math.random(1,#Letters)]))..((i == 2 and "-") or "") end print("Working") wait(15) script.Parent.Text = text end)