Sorry for posting a lot here, you can just ignore this if you don’t want to help. I just recently unlocked DevForum.
In my game, you can buy a car and it spawns on a pad. This pad FLOODS with cars, and it basically breaks the entire game. I’m trying to make it so the cars spawn on 1 of 6 pads, instead of 1. I’m trying to fiddle around with math.random, but I’m having trouble.
local function cloneFunc(vehicle)
vehicle.Parent = workspace
vehicle:MoveTo(Vector3.new(workspace.SpawnPad.Position.X, workspace.SpawnPad.Position.Y + 5, workspace.SpawnPad.Position.Z))
end
This solution simply picks a random child of the spawns Model, so you can just put any spawns in there (and you don’t have to name them anything).
Using math.random(min, max)
local spawns = workspace.Spawns --Or whatever location you store the spawns at
local function cloneFunc(vehicle)
vehicle.Parent = workspace
local spawnPad = spawns:GetChildren(math.random(1, #spawns:GetChildren()))
vehicle:MoveTo(Vector3.new(SpawnPad.Position + Vector3.new(0,5,0)) --Also simplified this line
end
Or using the Random.new function with :NextInteger(min, max) (works exactly the same way)
local randO = Random.new()
local spawns = workspace.Spawns --Or whatever location you store the spawns at
local function cloneFunc(vehicle)
vehicle.Parent = workspace
local spawnPad = spawns:GetChildren(randO:NextInteger(1, #spawns:GetChildren()))
vehicle:MoveTo(Vector3.new(SpawnPad.Position + Vector3.new(0,5,0)) --Also simplified this line
end