So I’m making simulator and I need help with a random part spawner,
How to make a part spawner that only spawns on one single base, but also randomly with maximum spawn?
So example here my stage 1 is grass and i need to spawn it only on this part, but randomly, plus with a limit.
You could reference a couple of your own variables, encase it inside a while true do loop, then “Clone” the parts by putting them inside ServerStorage first, and then retrieving them using the Clone() function if there’s enough CurrentParts:
local PartLimit = 10
local CurrentParts = 0
while true do
if CurrentParts < PartLimit then
PartLimit += 1
local RandomPosition = Vector3.new(math.random(-25, 25), 3, math.random(-25, 25))
local PartClone = game.ServerStorage.toy1:Clone()
PartClone.Parent = workspace
PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
end
wait(1)
end
local PartLimit = 10
local CurrentParts = 0
print("Running")
while true do
print("Loop running")
if CurrentParts < PartLimit then
PartLimit += 1
print("Cloning a part")
local RandomPosition = Vector3.new(math.random(-25, 25), 3, math.random(-25, 25))
local PartClone = game.ServerStorage.toy1:Clone()
PartClone.Parent = workspace
PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
end
wait(1)
end
You could just divide the X & Z values by 2 for getting the total Part’s Size & where you want the clones to spawn inside the script when the Position is called for cloning a part
local PartLimit = 10
local CurrentParts = 0
local Grass = workspace["Stage 1"].grass
print("Running")
while true do
print("Loop running")
if CurrentParts < PartLimit then
PartLimit += 1
print("Cloning a part")
local RandomPosition == Vector3.new(math.random(Grass.Position.X / -2, Grass.Position.X / 2), 10, math.random(Grass.Position.Z / -2 Grass.Position.Z / 2))
local PartClone = game.ServerStorage.toy1:Clone()
PartClone.Parent = workspace
PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
end
wait(1)
end
local PartLimit = 10
local CurrentParts = 0
local Grass = workspace["Stage 1"].grass
print("Running")
while true do
print("Loop running")
if CurrentParts < PartLimit then
PartLimit += 1
print("Cloning a part")
local RandomPosition == Vector3.new(math.random(Grass.Position.X / -2, Grass.Position.X / 2), 10, math.random(Grass.Position.Z / -2 Grass.Position.Z / 2))
local PartClone = game.ServerStorage.toy1:Clone()
PartClone.Parent = workspace
PartClone.Position = RandomPosition
end
wait(1)
end