Hello devs, thanks for reading my post!
So I just need some help or an explanation why my alphanumeric plate generator won’t work. It’s organized so that the TextLabel I want to randomize is a sibling of the script. My Code:
local PlateText = script.Parent.Plate.Text
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"}
-- Generate an alphanumeric plate
local Section1 = math.random(100, 999)-- Handle the numbers
local function Generate3Letters()
local Count = 0
local Result = ""
repeat
wait()
Result = Result .. Letters[math.random(1, #Letters)]
until Count == 3
return Result
end
local Section2 = Generate3Letters()
local FullPlate = tostring(Section1) .. " " .. Section2
PlateText = FullPlate
script:Destroy()
But the script results in just blank text.
If anyone could help me, it would be appreciated!
You are setting PlateText to the generated string, PlateText is just a variable with the original text of the license plate, instead you should do script.Parent.Plate.Text = FullPlate
math.randomseed(os.clock())
local PlateText = script.Parent.Plate -- by adding ".Text", you're assigning the variable the value of the property
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"}
-- Generate an alphanumeric plate
local Section1 = math.random(100, 999)-- Handle the numbers
local function Generate3Letters()
local Result = ""
for _ = 1, 3 do
Result ..= Letters[math.random(1, #Letters)]
-- use the "..=" compound operator (it's the same thing but less writing)
wait()
end
return Result
end
local Section2 = Generate3Letters()
local FullPlate = tostring(Section1) .. " " .. Section2
PlateText.Text = FullPlate -- assign the text the value
script:Destroy()
Because math.random() is not truly random (it uses a procedure called pseudo-randomization), math.randomseed(seed) sets seed to the random “seed”, which helps with the randomization of numbers.