im trying to randomly generate something with math.random and here is the script
local orb = game.Lighting.XP
while true do
local clone = orb:Clone()
clone.Parent = workspace.orbs
clone.Position = math.random(-2097.074, 14.905, 798.157, 2883.039, 9.157, -4183.502)
game.workspace.orbs.OrbsValue.Value = game.workspace.orbs.OrbsValue.Value + 1
wait()
if game.Workspace.orbs.OrbsValue.Value >= 100 then
break
end
end
while true do
local clone = orb:Clone()
clone.Parent = workspace.orbs
local map = "-2097.074, 14.905, 798.157, 2883.039, 9.157, -4183.502"
clone.Position = math.random(#map)
game.workspace.orbs.OrbsValue.Value = game.workspace.orbs.OrbsValue.Value + 1
wait()
if game.Workspace.orbs.OrbsValue.Value >= 100 then
break
end
end
No, if you want to make a random position just do:
local Positions = {
Vector3.new(20, 20, 20);
Vector3.new(10, 10, 10)
} -- Put here the possible positions
local RandomNumber = math.random(1, #Positions)
print(Positions[RandomNumber])
The math.random function has the following parameters and behaviors:
math.random(): Returns a random number between 0-1
math.random(x): Return a random integer between 0 and x
math.random(x, y): Returns a random integer between x and y
In your case, I’m going to make a guess that you have 2 different positions you want to be randomly chosen? In that case, you can throw those positions into a table, and then have math.random pick out a random index in the table, which will point to one of the positions.
local positions = {
Vector3.new(-2097.074, 14.905, 798.157),
Vector3.new(2883.039, 9.157, -4183.502),
}
...
local randomPosition = positions[math.random(1, #positions)]
clone.Position = randomPosition
If you’re wanting to randomly assign orbs around the map, you’d define X and Z as variables, carrying a random number given from math.random(), and add it to the center. Here’s an example:
local int = 0
while wait() do
int += 1
local clone = orb:Clone(); clone.Parent = game.Workspace
local x, z = math.random(-100, 100), math.random(-100, 100)
clone.Position = Vector3.new(x, 5, z)
if int == 100 then break end
end
while true do
local clone = orb:Clone()
clone.Parent = workspace.orbs
local randomnumber = math.Random(1,2)
if randomnumber == 1 then
clone.CFrame = CFrame.new(-2097.074, 14.905, 798.157)
elseif randomnumber == 2 then
clone.CFrame = CFrame.new(2883.039, 9.157, -4183.502)
end
game.workspace.orbs.OrbsValue.Value = game.workspace.orbs.OrbsValue.Value + 1
wait()
if game.Workspace.orbs.OrbsValue.Value >= 100 then
break
end
end