Model flickering in ViewportFrame

So I ended up not being able to figure out how to insert my Scroll from blender because it has constraints that are needed for the animation and ended up just importing each frame. For some reason, even though it has a crossfade the Scroll is still semi-transparent and flickers.

if script.Parent.Parent.Parent.Parent == game.StarterGui then return end

local ReplicatedStoarge = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local scrollFrames = {
	ReplicatedStoarge.Frames:WaitForChild("Frame2"),
	ReplicatedStoarge.Frames:WaitForChild("Frame3"),
	ReplicatedStoarge.Frames:WaitForChild("Frame4"),
	ReplicatedStoarge.Frames:WaitForChild("Frame5"),
	ReplicatedStoarge.Frames:WaitForChild("Frame6"),
	ReplicatedStoarge.Frames:WaitForChild("Frame7"),
	ReplicatedStoarge.Frames:WaitForChild("Frame8"),
	ReplicatedStoarge.Frames:WaitForChild("Frame9"),
	ReplicatedStoarge.Frames:WaitForChild("Frame10"),
	ReplicatedStoarge.Frames:WaitForChild("Frame11"),
	ReplicatedStoarge.Frames:WaitForChild("Frame12"),
	ReplicatedStoarge.Frames:WaitForChild("Frame13"),
	ReplicatedStoarge.Frames:WaitForChild("Frame14"),
	ReplicatedStoarge.Frames:WaitForChild("Frame15"),
	ReplicatedStoarge.Frames:WaitForChild("Frame16"),
	ReplicatedStoarge.Frames:WaitForChild("Frame17"),
	ReplicatedStoarge.Frames:WaitForChild("Frame18"),
	ReplicatedStoarge.Frames:WaitForChild("Frame19"),
	ReplicatedStoarge.Frames:WaitForChild("Frame20")
}

local blackListed = {
	"Frame1",
}

local viewPort = script.Parent
local frameDelay: number = 0.1

task.wait(3.5)

for index = 1, 19 do
	local framePrevious: Model = nil
	for _, frame in ipairs(script.Parent:GetChildren()) do
		if frame:GetAttribute("Blacklisted") ~= index - 1 then continue end
		framePrevious = frame
		break
	end
	
	local frameClone: Model = scrollFrames[index]:Clone()
	frameClone:ScaleTo(2)
	frameClone:PivotTo(framePrevious.WorldPivot)
	frameClone:SetAttribute("Blacklisted", index)
	for _, part in ipairs(frameClone:GetDescendants()) do
		if not part:IsA("BasePart") then continue end
		TweenService:Create(part, TweenInfo.new(0.1, Enum.EasingStyle.Linear), {
			Transparency = 0
		}):Play()
	end
	frameClone.Parent = script.Parent
	
	for _, part in ipairs(framePrevious:GetDescendants()) do
		if not part:IsA("BasePart") then continue end
		TweenService:Create(part, TweenInfo.new(0.1, Enum.EasingStyle.Linear), {
			Transparency = 1
		}):Play()
	end
	task.spawn(
		function()
			task.wait(0.1)
			framePrevious:Destroy()
		end
	)
	
	task.wait(0.1)
end

-- finds previous
-- clones new
-- fades previous
-- destroys previous
-- iterate

Try using Runservice.RenderStepped:Wait() instead of task.wait(0.1)

RenderStepped:Wait() halts a single frame, I don’t think that would fix the flickering issue and would only make the frame rate faster

Try not using a tween to change the transparency

How would you want me to change the transparency? Lerp?

True, what they should do instead is yield the script until all the tweens are done then destroy the previous frame.

1 Like

I think thats what they’re attempting to do, I think they just forgot to assign a variable to the magic numbers (i think its 0.1)

Why are you tweening the transparency, instead of just destroying the previous frame instantly and setting up the new frame?

It’s crossfading to try to prevent the flickering, it happens regardless of the transparency

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local PlayedFrames = {} -- frames played so far
local FrameDelay = 0.2 -- Delay before next frame

local Player = Players.LocalPlayer

local ScrollGui = Player.PlayerGui:WaitForChild("ScrollGui")
local ViewportFrame = ScrollGui.ViewportFrame

local Frames = ReplicatedStorage.ScrollFrames:GetChildren() -- Frame names are #'s
table.sort(Frames, function(f0, f1)
	return tonumber(f0.Name) < tonumber(f1.Name)
end)

task.wait(2) -- Delay before starting

for currentFrame = 1, #Frames do
	local previousFrame = PlayedFrames[currentFrame-1] :: BasePart
	if previousFrame then
		previousFrame:Destroy()
	end
	
	local frame = Frames[currentFrame]:Clone() :: BasePart
	frame.Parent = ViewportFrame
	
	PlayedFrames[currentFrame] = frame
	task.wait(FrameDelay)
end

Wasn’t sure if the flicker was intended or not but with this the flicker is gone
Hope this helps