ImageLabel.Image does not get set properly when used in spawn()

I have a little “game” inside my place where you press a bunch of buttons in order, and if you get them correctly it spawns a brick.

But I want it such that when you get it right, it sets the icon of an ImageLabel to green and then changes it to gray after 2 seconds without interrupting the main thread.

The issue is that whenever I try to set the image inside spawn it doesn’t get set properly and instead goes invisible.

Here is the code I had:

spawn(function()
	correctLight.Image = lightIcons.tick
	wait(2)
	correctLight.Image = lightIcons.tickGray
end)

If I instead use:

correctLight.Image = lightIcons.tick

The image does get set but if I use the full code like above, it won’t let you play until the icon goes gray again.

Make sure you are using the proper ImageID. Try inserting a decal in workspace, paste your ID, and use the ID that it returns.

Also, you can simplify your code like so:

correctLight.Image = lightIcons.tick
task.delay(2, function()
	correctLight.Image = lightIcons.tickGray
end)

It might also be turning invisible because by using spawn or delay, you are creating a new thread that runs separately from the script, so anything after the delay would be run first then what is inside the delay will be run within 2 seconds. Maybe remove the delay altogether and just keep it as:

correctLight.Image = lightIcons.tick
task.wait(2)
correctLight.Image = lightIcons.tickGray
1 Like