Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
It works, kind of. The script plays a fraction of sound not the whole song. ROBLOX_sammy048 28 — 4y
0
EEK Aiden_12114 79 — 4y
Ad

Answer this question