Why is this sound script not working?

The Parent is an imagebutton. I tried to make it change it’s image id but that doesn’t work either. The song doesn’t continue to play. I don’t understand where the error is.

Inside the the ImageButton there is a Sound, UICorner and the localscript:

script.Parent.Sound:Play()

script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Sound.IsPlaying then
  		script.Parent.Sound.Volume = 0
		script.Parent.Image = 6853258454
	else
		script.Parent.Sound.Volume = 0.5
		script.Parent.Image = 257126515
 end
end)```
2 Likes

instead of if script.Parent.Sound.IsPlaying then do Sound:Pause.

It just makes more sense. Get rid of the volume change as well.

plus, if that didnt work, change those ids to the EXACT link.

2 Likes

try this :

script.Parent.Sound:Play()
script.Parent.MouseButton1Click:connect(function()
if script.Parent.Sound.IsPlaying then
script.Parent.Sound.Volume = 0
script.Parent.Image = “rbxassetid//6853258454”
else
script.Parent.Sound.Volume = 0.5
script.Parent.Image = “rbxassetid//257126515”
end
end)

2 Likes

This doesn’t work, the imagine on the button doesn’t change, nor does the sound play

script.Parent.Sound.IsPlaying will always be true here even when you set the volume to 0 therefore the code inside the else bit will never run.

Instead of setting the volume to 0, you should just set Sound.Playing to false when you want to pause the sound, this will change the Sound.IsPlaying variable.

script.Parent.Sound:Play()

script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Sound.IsPlaying then
  		script.Parent.Sound.Playing = false
		script.Parent.Image = 6853258454
	else
		script.Parent.Sound.Playing = true
		script.Parent.Image = 257126515
 end
end)
1 Like

i am so sorry, i didnt check studio try this :

script.Parent.Sound:Play()

script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Sound.IsPlaying then
  		script.Parent.Sound.Playing = false
		script.Parent.Image = "rbxassetid://6853258454"
	else
		script.Parent.Sound.Playing = true
		script.Parent.Image = "rbxassetid://257126515"
 end
end)

@Rae3504 Showed this code I just replaced stuff for the image id

1 Like