How would I make a sound play only if a UI frame was visible?

Hi!
I am trying to make a UI for a shop in game. If the plsyer touches the door, it opens the UI.
That’s out for now. I am having trouble trying to do this script:

if script.Parent.Parent.Visible = true then
	script.Parent.IsPlaying = true
else
	script.Parent.IsPlaying = false
	script.Parent.TimePosition = 0
end

I’m getting this in the if then…
image
I know it means it has to be a var or something, but I have had if ___.visible = true in the past. What have I done wrong?
(And no, local SOUND_2 = script.Parent.Parent if SOUND_2.Visible = true then
did not gelp.

Just add another =, you aren’t defining it as a conditional argument I believe

== means if equal to, so why don’t you try doing

if script.Parent.Parent.Visible == true then
	script.Parent:Play()
else
script.Parent.IsPlaying = false
	script.Parent.TimePosition = 0
end

I don’t think isplaying is a value that you set its value you check to see if the sould isplaying you should use script.Parent:Play()
and script.Parent:Stop()
or something like this

image
Nice try.

sort of like what @golden_843 was saying it needs to be a Play() not a Play without the parentheses…

1 Like

Ummm you need to put the () after play its a function then it will work as long as your sound is the parent of your script. dont just type play type “:Play()”

1 Like