Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cloning model and having its position changed not working?

Hi! I previously asked how to clone corridors and i got some good responses, however, the script now seems to give me the error of:

10:33:26.279 Workspace.Script:7: attempt to index nil with 'PrimaryPart' - Server - Script:7

The script used:

local AmountOfCorridors = 0 

while true do
    local infgen = game.Workspace:FindFirstChild("original"):Clone()
    infgen.Name = "notorig"..AmountOfCorridors
    local pos = 
game:Workspace:FindFirstChild("notorig"..AmountOfCorridors).PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor 

    wait(.1)

    AmountOfCorridors = AmountOfCorridors+1 
    infgen:SetPrimaryPartCFrame(pos)
    wait(12)
end

Anyone have ideas? Thanks is advance!

1 answer

If it is a model, then just change PrimaryPart, if not then this code should be good

local AmountOfCorridors = 0 

while true do
	local infgen = game.Workspace:FindFirstChild("original"):Clone()
	infgen.Name = "notorig"..AmountOfCorridors
	if infgen:IsA("Model") then
		if infgen.PrimaryPart then
			local pos = 
				game.Workspace:FindFirstChild("notorig"..AmountOfCorridors).PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor 
		end
	elseif infgen:IsA("BasePart") then
		local pos = 
			game.Workspace:FindFirstChild("notorig"..AmountOfCorridors).CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor 
	end 

	wait(.1)

	AmountOfCorridors = AmountOfCorridors+1 
	infgen:SetPrimaryPartCFrame(pos)
	wait(12)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.