VHS Effect flickering off

  1. VHS Effect
local vhs = script.Parent

local StaticImages = {
	'rbxassetid://120418234923349';
	'rbxassetid://136113918166159';
}
while task.wait(0.05) do
	script.Parent.Image = StaticImages[math.random(1, #StaticImages)]
	vhs.Image = StaticImages[math.random(1, #StaticImages)]
end

This script flickers between 2 VHS overlays but sometimes it just flickers to nothing.

2 Likes

Vhs and script .Parent are the same thing. Did you mean to reference another gui element?

4 Likes

It looks like you called for the Main Overlay twice, maybe try somthing like this or alter your own script:

local vhs = script.Parent:WaitForChild("VHS")

local image1 = "rbxassetid://136113918166159"
local image2 = "rbxassetid://120418234923349"

local images = {image1, image2}

while task.wait(0.3) do
        local selectRandom = images[math.random(1, #images)]
        vhs.Image = selectRandom
end

If the problem continues, Let me know.

3 Likes

local image1 = "rbxassetid://136113918166159"
local image2 = "rbxassetid://120418234923349"

local images = {image1, image2}

while task.wait(0.1) do
	local selectRandom = images[math.random(1, #images)]
	script.Parent.Image = selectRandom
end

It’s doing the same thing. I’m not sure why its doing that.

1 Like

I think it happens because image is not loaded, but it shouldn’t happen more than 1 time, so its surely different reason

2 Likes

Actually just realized that it actually may happen because of that

Try having all images there and just enable and disable them (As Instances, turn their visible value)
(Like disable all images, then enable one and repeat)

2 Likes

you might need to check if the selectRandom is not nil before setting the image:

local image1 = "rbxassetid://136113918166159"
local image2 = "rbxassetid://120418234923349"

local images = {image1, image2}

while task.wait(0.1) do
	local selectRandom = images[math.random(1, #images)]
	if selectRandom then
		script.Parent.Image = selectRandom
	end
end
2 Likes

I dont think it can be nil, since it chooses between 1 and 2 and can’t choose 3 or more
Still good thought

2 Likes

Well i have another thought, i would use ContentProvider Service to load all images before Before starting the loop:

local image1 = "rbxassetid://136113918166159"
local image2 = "rbxassetid://120418234923349"

local images = {image1, image2}

game:GetService("ContentProvider"):PreloadAsync(images)

while task.wait(0.1) do
    local selectRandom = images[math.random(1, #images)]
    script.Parent.Image = selectRandom
end

2 Likes

Didn’t know you can do that
By the way how I would make actual loading screen to wait till all assets load cuz I don’t know how to get all assets and loaded one’s (Just wanting to know how to get all assets in-game and the loaded ones)

2 Likes

Thats weird, I tried testing it in my own session with the same ID’s and I didnt have that problem. Are there any other GUI elements with seperate scripts under the same ScreenGui?

2 Likes

You could get all paths you want (wouldnt suggest going through the whole game as it will take a while if you have a huge game):

local Paths = {workspace,game:GetService("ReplicatedStorage"),game.Players.LocalPlayer.PlayerGui}

and loop through the table preloading each asset and adding them in pcall to know which asset failed to load and which asset loaded:

for i, asset in ipairs(Paths) do
	local success, result = pcall(function()
		return game:GetService("ContentProvider"):PreloadAsync({asset})
	end)
	if not success then
		warn("Failed to preload asset:", asset)
	end
end
4 Likes

Here is a video from my POV:


With this script:

local vhs = script.Parent:WaitForChild("VHS")

local image1 = "rbxassetid://136113918166159"
local image2 = "rbxassetid://120418234923349"

local images = {image1, image2}

while task.wait(0.3) do
        local selectRandom = images[math.random(1, #images)]
        vhs.Image = selectRandom
end
2 Likes

Yeah this seems to be a common problem. It looks like Roblox removes images from memory sometimes, so it takes a brief moment to load them on to the screen, even when they’re preloaded in some cases.

I would create two separate image labels, then use the ImageLabel.ImageTransparency of the two ImageLabels to flip between the images.

Here are some threads about this:

3 Likes

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