Make sure you know what your writing, and why you’re writing it. If you don’t get past that point, you’re going no where. So I’m going to give you precise details about why your code is horrible, and how to fix it.
First of all:
[lua]ply:SetPos(Vector(math.random(1, #citizenspawn)))[/lua]
math.random(1, #citizenspawn) will return you a number between 1 and the size of citizenspawn. Since the size of your current table is 2, it could either mean ply:SetPos(Vector(1))) or ply:SetPos(Vector(2))).
Not making much sense, right?
What you would it to do is access one of the elements of the table chosen randomly, I hope you know how to access an element inside of a table, so your code should look like this now:
[lua]ply:SetPos(Vector(citizenspawn[math.random(1, #citizenspawn)]))[/lua]
Now look at the two different possibilities, that could either mean this:
[lua]ply:SetPos(Vector(“4524.13, 2885.91, 458.13”))[/lua]
or this:
[lua]ply:SetPos(Vector("-552.53, -3.28, 274.13"))[/lua]
This still does not make sense, because Vector takes 3 numerical values, and not strings. Anything between double quotes or quotes are literal strings that have about as much mathematical value as “Hello world”.
Your best bet is to store the positions directly as vectors inside of your table. Like this:
[lua]local citizenspawn =
{
Vector(4524.13, 2885.91, 458.13),
Vector(-552.53, -3.28, 274.13),
}[/lua]
This way, all you have to do after that is:
[lua]ply:SetPos(citizenspawn[math.random(1, #citizenspawn)])[/lua]
Also, since you seem to be a Lua beginner, please don’t have bad habits such as adding semicolons at the end of every line, this is Lua, not C. Although semicolons work, they are completely useless, a line of code with or without a semicolon will do exactly the same things.
Additionally, Lua comments are – and --[], and not // and /* */. Logical operators in Lua are “not”, “and” and “or”, and definitely not “!”, “&&” and “||”. There is absolutely no interest in writing “if(a==b)” instead of “if a==b”, unless you honestly think it is easier to read.
If you see those things in other people’s code, ignore them and do not imitate them, unless you really think writing like that makes things clearer.
Wrote a little more than I should, but hope that helped!