Image not appearing when changed

I am trying to make a Mute Music button that changes to a volume-muted icon. Unfortunately, the image is not changing and just seems to disappear when I try to change it after clicking the button. I have tried using multiple asset ID URLs, and yet none of them work. I am very confused as to what is happening.

Here is my code:

local Button = script.Parent
local Music = game.Workspace.Game.Utilities:WaitForChild("Player")
local Muted = Button.Muted.Value
local precursor = "rbxassetid://"
Muted = false

function onMouseClick()
	if Muted == false then
		print("Muting...")
		Button.Image = precursor.."4807438939"
		Music.Volume = 0
		Muted = true
		print("Finished.")
	else
		print("Unmuting...")
		Button.Image = precursor.."4807426713"
		Music.Volume = 0.5
		Muted = false
		print("Finished.")
	end
end

Button.Activated:Connect(onMouseClick)

Everything besides the image is working perfectly fine, and the output just says the print statements. No errors at all.

1 Like

That could be the issue, here are the links so you can see for yourself:
Muted Icon:

Unmuted Icon:

Yeah, the unmuted icon has nothing for me, so my guess is probably correct.

But if the waiting yields nothing, then there is another option. I have come to notice that directly copy-pasting assed IDs into scripts don’t work. So, for that you can first insert the asset ID into the Image property of an ImageLabel / ImageButton and then press enter. Click on the property again and copy that and paste it into the script. For some reason, it readjusts the asset ID when put into an Image element so that it’s different from the one in your URL bar.

4 Likes

Alright, thanks a lot! I’ll try this with my script.

1 Like

Put this script, into a GUI.
And put, music, in StarterGUI too! It will work, I think.

Script
Music = script.Parent.Parent.Parent.Sound

hidden = 1

function RunGui()

if hidden == 1 then

hidden = 2

script.Parent.Text = "Unmute Music"

Music.Volume = 0

else

hidden = 1

script.Parent.Text = "Mute Music"

Music.Volume = 0.4

end

end

script.Parent.MouseButton1Down:connect(RunGui)

This does not help with the issue. I am trying to fix my image that is suddenly disappearing when the GUI button is clicked.

Instead of concatenating the precursor and asset id, I suggest to just write out the phrase…

"rbxassetid://4807438939"

Also, your muted icon did not render properly. https://www.roblox.com/library/4807438939/Volume-Off

The easiest, way is, just add a frame, into GUI. You don’t need, script for it.

Yes you would… how would you even be able to detect a click without a script…

I am talking, about the image. He doesn’t needs, to try hard on image script. You can put a frame and asset ID trough properties.

Have you read my script at all? I am changing the image through a script. I already have one set, but I want it to change via a script when a button is activated.

Then wait, some time, to image appear in Roblox decals. As I said, use a frame.

Take away this line. (300000)

It’s a way of knowing if the music is already off or on. When the player clicks the button, if Muted is false, then stuff happens and Muted will be set to true. If Muted isn’t false, it’ll do the opposite. In the beginning, the music is on, so Muted = false.

But you set Muted to false, so it would be false no matter what.

If I am testing a script for music, if I want to turn on Muted and later on forget to turn it back off, this line of code ensures the code actually works.

Nvm, thought

Button.Image = precursor.."4807438939"

Was the original image, not the image it’s supposed to change to.

Can you show a video of what happens? Maybe that will help.