Help with random part generation

Greetings developers!

I come to you with a quest. In all seriousness, I need help randomly generating parts.

my script:

local Pos1 = Vector3.new(0,-3,0)
local Size1 = Vector3.new(5,5,5)

local BasePart = Instance.new("Part")
BasePart.Anchored = true
BasePart.Parent = workspace
BasePart.Position = Pos1
BasePart.Size = Size1

local clone1 = BasePart:Clone()
clone1.Position = Pos1 + Vector3.new(4.999, 0, 0)
clone1.Parent = workspace
local clone2 = BasePart:Clone()
clone2.Position = Pos1 + Vector3.new(0, 0, 4.999)
clone2.Parent = workspace
local clone3 = BasePart:Clone()
clone3.Position = Pos1 + Vector3.new(-4.999, 0, 0)
clone3.Parent = workspace
local clone4 = BasePart:Clone()
clone4.Position = Pos1 + Vector3.new(0, 0, -4.999)
clone4.Parent = workspace

for i,v in pairs(workspace:GetChildren()) do
		if v:IsA("Part") and v.Name == "Part" then
			local x = v:Clone()
			x.Position = x.Position * Vector3.new(2,1,2)
	end
end

It generates the base part and the clones which serves as a base for the game. It doesn’t actually generate the parts at all. The problem is the for loop.

I really just want it to infinitely duplicate parts and fill out a huge area. Feel free to ask questions.

edit: there is a spawn location in the workspace located at 0, 0, 0. not sure if it’s relevant.

Thank you in advance!
Any help much Appreciated.

  • vet

If you want it to generate parts forever, you can use a while wait() do, and put the for i loop inside that… It should be like this:

while wait() do
-- do whatever
end

I know that part. The issue is that it won’t generate anything in the for loop.

When you cloned the part in the loop, you never set its parent, meaning that the parent would automatically be nil. You have to set the parent to game.Workspace for it to show. Try this:

x.Parent = game.Workspace

Thanks man! I really thought that when you cloned something, it kept the same parent.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.