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 3 years ago
Edited 3 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:

01local AmountOfCorridors = 0
02 
03while true do
04    local infgen = game.Workspace:FindFirstChild("original"):Clone()
05    infgen.Name = "notorig"..AmountOfCorridors
06    local pos =
07game:Workspace:FindFirstChild("notorig"..AmountOfCorridors).PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor
08 
09    wait(.1)
10 
11    AmountOfCorridors = AmountOfCorridors+1
12    infgen:SetPrimaryPartCFrame(pos)
13    wait(12)
14end

Anyone have ideas? Thanks is advance!

1 answer

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

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

01local AmountOfCorridors = 0
02 
03while true do
04    local infgen = game.Workspace:FindFirstChild("original"):Clone()
05    infgen.Name = "notorig"..AmountOfCorridors
06    if infgen:IsA("Model") then
07        if infgen.PrimaryPart then
08            local pos =
09                game.Workspace:FindFirstChild("notorig"..AmountOfCorridors).PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor
10        end
11    elseif infgen:IsA("BasePart") then
12        local pos =
13            game.Workspace:FindFirstChild("notorig"..AmountOfCorridors).CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor
14    end
15 
View all 21 lines...
Ad

Answer this question