Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a Sound play when a Frame is Visible?

I've been trying to make a script for my game that makes a Sound/Music play when a frame is visible and it will stop when it's Invisible, I have attempted to make the script on my own but since I'm a beginner I don't know how...

I've put the script below (excuse the clutter.) Any help would be appreciated. :)

--Script--

local Mapvote = script.Parent.Parent
local music = script.Parent
local musicPlaying = false
local audioID = 4814920271 
local sound = Instance.new("Sound", music)
sound.SoundId = 'rbxassetid://'..audioID

if Mapvote.Visible == true then
		if(musicPlaying == false) then
		sound:Play() 
		musicPlaying = true 
	else
		sound:Stop() 
		musicPlaying = false 
	end
	end

1 answer

✓ Accepted answer

I think all you have to do is put it in a loop.

local Mapvote = script.Parent.Parent
local music = script.Parent
local musicPlaying = false
local audioID = 4814920271 
local sound = Instance.new("Sound", music)
sound.SoundId = 'rbxassetid://'..audioID

while wait(0.2) do
	if Mapvote.Visible == true then
        if(musicPlaying == false) then
        sound:Play() 
        musicPlaying = true 
    else
        sound:Stop() 
        musicPlaying = false 
    end
    end
end

2 comments

0

It works, kind of. The script plays a fraction of sound not the whole song.

0

EEK

This discussion is preserved as it was. New answers, comments, and votes are closed.