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

How would i generate 4 random number ?

Asked by 6 years ago

I'm making a license plate generator for a car so i did this

script.Parent.Text = math.random(0,9)math.random(0,9)math.random(0,9)math.random(0,9)

but it's only set 1 value but i needed 4

0
Learn Lua cabbler 1942 — 6y
0
@cabber ik lua but i just need to get 4 number but idk how ???? xJathur95x 129 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Problem

math.random() does return a randomly generated value and all 4 of your math.random() functions are returning a value. Only 1 is being used since you need to concatenate the numbers together.

Concatenating Strings

Concatenation is essentially adding/joining things together. With Lua, you concatenate strings with the .. operator.

An example:

local x = "This is a "
local y = "string!"

print(x.." "..y) -- this prints "This is a string!"

In your case, you need to first, convert the randomly generated numbers into strings. This can be done with the tostring()method. Secondly, you need to concatenate or join the randomly generated numbers together, to form one full string.

Here is the final code:

script.Parent.Text = tostring(math.random(0, 9))..tostring(math.random(0, 9))..tostring(math.random(0, 9))..tostring(math.random(0, 9))

Feel free to ask any questions, hope this helped!

0
:o Thanks ! xJathur95x 129 — 6y
Ad

Answer this question