I tried using the or
function, but that just returned the first set of numbers and not the second, so it always spawn in the same general area. Is there an easy way to do this, or do I need to create random values that dictate these ones...
local pos = Vector3.new((math.random(-150,-25)or math.random(25,150)),0,(math.random(-150,-25)or math.random(25,150)))
You could make a table of possible choices, and retrieve them using a function whenever you need them.
local choices = {25, -25, 50, -50} local function rand () return choices[ math.random( #choices ) ] end print(rand(), 1, rand()) --Vector3.new(rand(), 0, rand())
While ImageLabel's way is very correct, I am going to go into further detail, and create a table of random numbers.
let's start by creating a table that will hold all of our numbers.
numbers = {}
now we can setup a function that's going to generate our table. Additional detail will be given in the comments.
function GenerateTable() checkNumber = false -- We will set this to true if the number already exists. Won't happen commonly, but just in case. for i = 1, 50 do -- Generate 50(ish) random numbers for _,v in pairs(numbers) do local randomNumber = math.random(0,100) -- Our random number if randomNumber == v then checkNumber = true --Uh oh, already exists. This is where the 50(ish) comes into play. If this happens, it will only generate 49 (unless it happens multiple times. Very unlikely). end end if not checkNumber then table.insert(numbers, randomNumber) end end end
that we have a random set of numbers, about 50 of them, we can refer back to ImageLabel's answer for the rest.
function generateNumber() return numbers[math.random(1,#numbers)] end
Hope I helped.