Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cloning model and having its position changed not working?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
1
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

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
Ad

Answer this question