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
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.
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.
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.