how to make random spawn with math.random also my baseplate is not flat and its terrain thats mostly why i dont know how to make this and here is the terrain
local orb = game.Lighting.XP
while true do
local clone = orb:Clone()
clone.Parent = workspace.orbs
game.workspace.orbs.OrbsValue.Value = game.workspace.orbs.OrbsValue.Value + 1
wait()
if game.Workspace.orbs.OrbsValue.Value >= 100 then
break
end
clone.Position = math.random() -- here i dont know how to randomize this
end
Though it’s a little more tedious, you could create a randomized spawning system using spawns for said orbs. Of course, this method has benefits (stop the orbs from spawning in certain locations (such as walls)). The randomizer script is something along the lines of:
local orbspawn = game.Workspace.Spawns:GetChildren()[math.random(1, #game.Workspace.Spawns:GetChildren())]
That line of code randomly selects an instance in another instance.
local orbspawn =--[[defines the variable]] game.Workspace.Spawns:GetChildren()--[[gets the children]][math.random(1, #game.Workspace.Spawns:GetChildren()--[[gets the number of children and uses math.random to select a random child by using index]])]
It’s kind of like using local part = game.Workspace.Part, as it gets an instance and defines it in a variable.
I’d recommend getting a random X and Y position by using math.random() between predetermined ranges that you want the XP Orbs to spawn in. Once you have those you can create a Vector3 with your randomized X and Y coordinates, and a Y coordinate of about 10 studs above the highest point in your map.
Use workspace:Raycast() to create a raycast from the randomized Vector3 pointing towards the ground and spawn the orb a few studs above where they meet.
Hello, is this more of what you’re asking for? If you have any questions feel free to ask.
--|< Varaibles >|--
local orb = game.Lighting:WaitForChild("XP");
local orbsFolder = workspace:WaitForChild("orbs");
local orbsValue = orbsFolder:WaitForChild("OrbsValue");
local maxOrbs = 100;
local waitTime = 0.1;
--|< Main >|--
while orbsValue.Value < maxOrbs do
local clone = orb:Clone();
clone.Parent = orbsFolder;
orbsValue.Value = orbsValue.Value + 1;
local randomX = math.random(-50, 50);
local randomY = math.random(5, 20);
local randomZ = math.random(-50, 50);
clone.Position = Vector3.new(randomX, randomY, randomZ);
task.wait(waitTime);
end