Generation Map help

  1. What do you want to achieve? Keep it simple and clear!
    Wanted to create a branch by using a center’s end

  2. What is the issue? Include screenshots / videos if possible!


    the bug was caused when End’s parent switched, End’s Position switched to Start and So Generation generates a Branch ON the End’s new position instead a old one.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None, not related to my generations system

here a script

for _, End in pairs(workspace.Map:GetDescendants()) do
	local thing = 0
	if End.Name == "End" then
		thing += 1
		local folder = Instance.new("Folder",workspace)
		local model = Instance.new("Model",folder)
		model.Name = "StartingPoint"
		
		folder.Name = "Major Center "..thing
		End.Parent = model
		model.Parent = folder
		for ip = 1,math.random(1,20) do
			for il = 1, math.random(1,10) do




				local function ASHH (weightedTable)

					for _, model in pairs(Model["longstair type"]:GetChildren()) do
						local weight = math.random(1, 100) -- You can customize this
						weightmodel2[#weightmodel2 + 1] = {
							Model = model,
							Weight = weight
						}
					end

					local totalWeight = 0

				
					for _, item in ipairs(weightedTable) do
						totalWeight = totalWeight + item.Weight
					end


					local randomPick = math.random(1, totalWeight)

		
					local currentWeight = 0
					for _, item in ipairs(weightedTable) do
						currentWeight = currentWeight + item.Weight
						if randomPick <= currentWeight then
							return item.Model
						end
					end
				end

				local chosenModel = ASHH(weightedModels)




				local children = folder:GetChildren()
				local past = children[IDIIDID]
				if past then
					IDIIDID = IDIIDID + 1
					local modelClone = chosenModel:Clone()
					modelClone:PivotTo(past.End:GetPivot())
					modelClone.Parent = folder
					modelClone.Name = modelClone.Name.." "..IDIIDID
					past.End.Name = "CapturedEND"
					print(modelClone.Parent.Name)

				end
			end

			local function ASHH (weightedTable)

				for _, model in pairs(Model["Center type"]:GetChildren()) do
					local weight = math.random(1, 100) -- You can customize this
					TableCenter2[#TableCenter2 + 1] = {
						Model = model,
						Weight = weight
					}
				end




				local totalWeight = 0

			
				for _, item in ipairs(TableCenter) do
					totalWeight = totalWeight + item.Weight
				end

		
				local randomPick = math.random(1, totalWeight)

			
				local currentWeight = 0
				for _, item in ipairs(TableCenter) do
					currentWeight = currentWeight + item.Weight
					if randomPick <= currentWeight then
						return item.Model
					end
				end
			end

			local chosenModels = ASHH(weightedModels)



			local children = folder:GetChildren()
			local past = children[IDIIDID]
			if past then
				IDIIDID = IDIIDID + 1
				local modelClone = chosenModels:Clone()
				modelClone:PivotTo(past.End:GetPivot())
				modelClone.Parent = folder
				modelClone.Name = modelClone.Name.." "..IDIIDID

				for i = 1,math.random(1,1)  do
					local children = modelClone["Randomizers END"]:GetChildren()

					local randomIndex = math.random(1, #children)
					children[randomIndex]:Destroy()

				end
				local lastEND = modelClone["Randomizers END"].End
				lastEND.Parent = modelClone

			end
		end
	end
	end


Visual issues