So, I have a viewport frame script that puts in a certain object when you select something (basically when the gui pops up). one problem, the object doesnt appear in the viewport frame (although its parented under it.). The thing that baffles me the most is that a script thats almost the same works for a gui that always appears. heres my function for the viewport frame.
The reason It creates a new clone of the object every .1 seconds is for the animation.
local function ChangeViewport(towerName)
repeat
wait()
until game:IsLoaded()
local run = game:GetService("RunService")
local debris = game:GetService("Debris")
local tower = nil
if towerName ~= "Unit" then
tower = towerName.Config.OriginalTower.Value
local anim = game.Workspace.ViewportFrames[tower].Humanoid:LoadAnimation(game.Workspace.ViewportFrames[tower].Animations.Idle)
anim.Looped = true
anim:Play()
end
while wait(0.1) do
if tower then
if game.Workspace.ViewportFrames[tower] then
local children = game.Workspace.ViewportFrames[tower]:Clone()
for i,v in pairs(children:GetChildren()) do
if v:IsA("Part") or v:IsA("MeshPart") then
v.Anchored = true
end
end
children.Parent = script.Parent.Selection.TowerViewport
debris:AddItem(children, 0.11)
end
else
return
end
end
end