Sound plays when gui is enabled

Hello,
I am a bit confused on how to make a sound play when my intro GUI is visible, could anyone help?

Many thanks :slight_smile:,
Spen_z.

if intro.Visible == true then
sound:Play()
else
sound:Stop()
end

To add one to what daslick said, you can use a function caller for the if then statement to be fired. Such as a click detector, loops, etc.

You could use the :GetPropertyChangedSignal method to get the event signal for when a specified property is changed (in this case .Enabled) then connect a function to that event signal which plays the sound.

Example:

-- assuming there's a sound inside the gui and that the localscript is in the gui
local Gui = script.Parent
local Sound = Gui.Sound

Gui:GetPropertyChangedSignal('Enabled'):Connect(function()
if Gui.Enabled then
Sound:Play()
end
end)
1 Like

This property changed signal was the reason the script wasn’t working at all

dead topic but anyways

while wait(5) do
if example.Visible == true then
Sound:Play
end
1 Like

package com.game.main;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.sound.sampled.Clip;
import javax.swing.JFrame;

import com.game.main.AudioPlayer;
import com.game.main.BufferedImageLoader;
import com.game.main.GameObject;
import com.game.main.Handler;
import com.game.main.KeyInput;
import com.game.main.ObjectId;
import com.game.main.Texture;

public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = -240840600533728354L;

public static final int WIDTH = 640;
public static final int HEIGHT = WIDTH / 12 * 9;
public static final String TITLE = “2D Space Game”;

private Thread thread;
private boolean running = false;

public static boolean paused = false;
public int diff = 0;
//0 = normal
//1 = hard

public static int frames = 0;

private Random r;
private Handler handler;
private HUD hud;
private Spawn spawner;
private Menu menu;
private static Clip clip;

public static BufferedImage sprite_sheet = null;

public static enum STATE {
Menu,
Select,
Help,
Game,
End
};

public static STATE gameState = STATE.Menu;

public Game() {

handler = new Handler();
hud = new HUD();
menu = new Menu(this,handler,hud);

this.addKeyListener(new KeyInput(handler));
this.addMouseListener(menu);

BufferedImageLoader loader = new BufferedImageLoader();
sprite_sheet = loader.loadImage("/sprite_sheet.png");