Hello !
I wanted to make a system where, as the time goes further, more objects would spawn. Pretty simple first look, but i can’t find a proper way to do it.
I have this spawn script :
function SpawnPart()
local part = Instance.new('Part');
part.Parent = workspace;
local x, y, z = math.random(0, 5), math.random(0, 5), math.random(0, 5);
part.Size = Vector3.new(x, y, z);
print("Part spawned !");
end
while wait() do
SpawnPart();
end
I think this should work but I am not sure so try it at your own risk.
function SpawnPart()
local part = Instance.new(‘Part’);
part.Parent = workspace;
local x, y, z = math.random(0, 5), math.random(0, 5), math.random(0, 5);
part.Size = Vector3.new(x, y, z);
print(“Part spawned !”);
end
Inside the parenthesis of wait before break put the amount of seconds you want the code to run for. If you do not enter the time it will run till infinity and crash your computer.
Just create a variable of the amount of objects to spawn
local partsToSpawn = 5
local function spawnParts()
for i = 1, partsToSpawn do
local part = Instance.new("Part", workspace)
local local x, y, z = math.random(0, 5), math.random(0, 5), math.random(0, 5)
part.Size = Vector3.new(x, y, z)
end
end
while wait(1) do
spawnParts()
partsToSpawn = partsToSpawn * 2
end
local SpawnableParts = 1
while wait(1) do
for _ = 1, SpawnableParts do
local Part = Instance.new("Part")
Part.Size = Vector3.new(
math.random(0, 5),
math.random(0, 5),
math.random(0, 5)
)
Part.Parent = workspace
end
SpawnableParts += 1
end
local startTime = os.time();
function Multiply()
return (os.time() - startTime);
end
function Spawn()
local part = Instance.new('Part');
part.Parent = workspace;
local x, y, z = math.random(0, 5), math.random(0, 5), math.random(0, 5);
part.Size = Vector3.new(x, y, z);
print("Part spawned !");
end
while true do
Spawn()
wait(1/Multiply)
end