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