Despite preloading decals, they still take some time to load

I’m trying to make a blinking system in my game. It consists of changing the Texture to a different sprite. However, the ClosedEyes decal takes a long time to load, leading to a blank face for about half a second.

It is a LocalScript in StarterPlayerScripts.

--// services
local service_players = game:GetService("Players")

--// player elements
local player_local = service_players.LocalPlayer
local instance_character = player_local.Character or player_local.CharacterAdded:Wait()
local instance_head = instance_character.Head

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

game.ContentProvider:PreloadAsync({"rbxassetid://6116240995", "rbxassetid://6114662224"})

while true do
	task.wait(math.random(1, 4))
	instance_head.Decals.Eyes.Texture = "rbxassetid://6116240995"
	task.wait(0.7)
	instance_head.Decals.Eyes.Texture = "rbxassetid://6114662224"
end
2 Likes

You have two task.wait() functions. This is what will be causing that error.

Those are on purpose, the first one is for the starting of the blink, and the second is for the small delay.
Even if I set the second one to a large number like 10, the decal still delays in loading by about half a second.

I think this might be some weirdness with Decal IDs vs Image IDs. Try adding a print after setting the eyes texture:

while true do
	task.wait(math.random(1, 4))
	instance_head.Decals.Eyes.Texture = "rbxassetid://6116240995"
	task.wait()
	print(`Set: "rbxassetid://6116240995", got: {instance_head.Decals.Eyes.Texture}`)
	task.wait(0.7)
	instance_head.Decals.Eyes.Texture = "rbxassetid://6114662224"
	task.wait()
	print(`Set: "rbxassetid://6114662224", got: {instance_head.Decals.Eyes.Texture}`)
end

See what it says in the output, if the value after “got” is different from the value after “set”, then you are using the wrong ID to preload the image.

The ID remains the same, do you think I should file a bug report?

Yeah, that it quite strange, but look for any bug reports that have already been made on this issue, I recall seeing one a while ago where PreloadAsync just didn’t work.

I appear to have found a bug report with this issue already:

Well, I have to scrap it now. Thanks for your help.
Hopefully Roblox fixes this issue in due time.

I am certain it won’t be very noticeable, after all it only happens once.

It doesn’t. It repeats again and again for me.
However, I’ve found a temporary solution:

Really hacky, but it works I guess.

Actually, you can try something else:

local Eyes1 = Instance.new("Decal")
Eyes1.Texture = "rbxassetid://6116240995"
local Eyes2 = Instance.new("Decal")
Eyes2.Texture = "rbxassetid://6114662224"

game:GetService("ContentProvider"):PreloadAsync({Eyes1, Eyes2})

I found a post:

That stated using strings to preload assets will result in PreloadAsync assuming they are images, and since you are using decals, this could be the cause of this issue.

This is also how the example code in the API documentation for PreloadAsync functions.

1 Like

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