# Help with viewport frames!

Hey guys! Currently cooking up a little project but ran into a tiny problem. When updating the viewport frame, parts cloned into it that have a material glitch out (guessing this happens because the material keeps changing per update). I can’t seem to fix it, so if anyone has any suggestions on how to fix this dilemma that would be great. Thanks for your time!

WHATS BASICALLY HAPPENING:

``````    VIEWPORTFRAME:ClearAllChildren()
for _, Part in next, Enviroment:GetDescendants() do
if (Part:IsA("BasePart")) then
Part:Clone().Parent = VIEWPORTFRAME
end
end``````
1 Like

Cloning BaseParts (Parts, MeshParts, Unions) produces different material patterns. This is to lessen the repeating patterns of materials when there are multiple parts with the same material placed close to each other.

If what you are trying to do is projecting the sand and grass patches in a portal, I suggest you clone objects once, link the original and cloned parts, and in the loop, just copy the Position and Rotations instead from the original part to the cloned one.

One way to link parts can be like this:

``````local Parts = {}

local Part1, Part2 = Instance.new("Part", workspace), Instance.new("Part", workspace)

-- You can use any Instance as a value's key in a dictionary.
Parts[Part1] = Part2

-- Now, in the loop, you can take the original part's position and rotation, and do fancy stuff with it to make it look like a portal.

for Original, Cloned in Parts do
local Original_Position, Original_Rotation = Original.Position, Original.Rotation
-- calculation stuff
end
``````

Sorry for this really late response… but I’m confused (LOL). Could you explain this a little bit more?

When you clone or create a new Part, Roblox will change the texture of the material a bit so that it would have variation.

[These are identical parts, but their textures are different from each other.]

This should explain as to why you see that “issue”, which is intended behavior. When you constantly make new parts, those parts will have varying textures, but since you replace them in the next frame with another set of cloned parts, those cloned parts also have varying textures. This creates that trippy effect.

If what you want to do is a portal-like effect, I suggest you clone the parts only once, instead of repeatedly cloning and destroying them (too much lag when many parts are being cloned). You can then just use the original parts’ properties when updating the cloned items.

1 Like

So theoretically would something like this work?

``````local Env = {}
for _, Part in ipairs(game:GetService("Workspace").Enviroment:GetDescendants()) do
if (Part:IsA("BasePart")) then
local Clone = Part:Clone()
table.insert(Env, {["Original"] = Part, ["Cloned"] = Clone})
end
end
``````

Yes, it should. What I would do though is:

``````local Env = {}

for _, Part in workspace.Environment:GetDescendants() do
if Part:IsA("BasePart") then
Env[Part] = Part:Clone() -- Use the original part as a key, and a clone of the part as the value.
end
end

-- The method above is valid, and you can simply get both parts like:

for Original, Clone in Env do -- Both the variables Original and Clone are parts.
Clone.Position = Original.Position
-- or whatever you would do with the two parts.
end
``````

I am getting this very odd error.
`The Parent property of Part is locked, current parent: NULL, new parent ViewportFrame`

What does your code look like now?

``````local Env = {}
for _, Part in Enviroment:GetDescendants() do
if (Part:IsA("BasePart")) then
Env[Part] = Part:Clone()
end
end
``````
``````	for Original, Clone in Env do
if (VisibleFromCFrame(nextCF, Original)) then
local offset = nextCF:Inverse() * Original.CFrame
Clone.CFrame = lastCF * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * offset
Clone.Parent = UIA.ViewportFrame
end
if (VisibleFromCFrame(lastCF, Original)) then
local offset = lastCF:Inverse() * Original.CFrame
Clone.CFrame = nextCF * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * offset
Clone.Parent = UIB.ViewportFrame
end
end
``````

The error being on the line setting the Clone parent. It says that the Parent Property is locked for some reason.

These two `if` blocks could cause some conflict with parenting a cloned part. If both conditions are true, the code will try to parent the cloned part twice, which can cause the error.

You should try using an `if-elseif` block. This makes sure that only one condition will be active, although the results will be based on the order of conditions. It shouldn’t matter though.

``````if (VisibleFromCFrame(nextCF, Original)) then
local offset = nextCF:Inverse() * Original.CFrame
Clone.CFrame = lastCF * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * offset
Clone.Parent = UIA.ViewportFrame
elseif (VisibleFromCFrame(lastCF, Original)) then
local offset = lastCF:Inverse() * Original.CFrame
Clone.CFrame = nextCF * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * offset
Clone.Parent = UIB.ViewportFrame
end
``````

This still errors “The Parent property of Part is locked, current parent: NULL, new parent ViewportFrame”

Are you still clearing the children of the ViewportFrame?

I have like no brain cells left lmao. Thanks, happy Halloween!

1 Like

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