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

How can I loop audio for a certain time limit? [closed]

Asked by 6 years ago

So far I've got this... But I want to make it so that after 10 minutes of one sound on repeat, a different audio plays? What am I doing wrong here? Do I need to add a loop in this script? If so how can I do that without breaking it?

local settings = require(script.Parent.Settings)

if settings.UseGlobalBackgroundMusic == false and settings.UseMusicZones == false then
    error("Cindering's BGM error: You have disabled both Global Background Music and Music Zones. You must change at least one of these settings to 'true'.")
    return
end

local name1 = "[1] Global Background Music"
local name2 = "[2] Background Music Zones"

local container = Instance.new("Folder")
container.Name = "CinderingBGM"

script.Parent.Settings.Parent = container

script.LocalBackgroundMusic.Parent = game.StarterPlayer.StarterPlayerScripts

local music = Instance.new("Folder")
local zones = Instance.new("Folder",music)
zones.Name = "MusicZones"
local global = Instance.new("Folder",music)
global.Name = "GlobalMusic"

if settings.UseMusicZones == true then
    local folder = script.Parent:FindFirstChild(name2) or game.ReplicatedStorage:FindFirstChild(name2) or workspace:FindFirstChild(name2) or game:FindFirstChild(name2,true) -- never know where someone might accidentally drag that folder...

    if folder then
        for _,model in pairs(folder:GetChildren()) do
            if (model:IsA("Model") and model:FindFirstChild("Music")) then
                model.Parent = zones
            end
        end
    else
        error("Cindering's BGM error: Your background music zones folder could not be found! You may have deleted/renamed the original folder. It should be named: "..name2)
        return
    end
end

if settings.UseGlobalBackgroundMusic == true then
    local folder = script.Parent:FindFirstChild(name1) or game.ReplicatedStorage:FindFirstChild(name1) or workspace:FindFirstChild(name1) or game:FindFirstChild(name1,true)

    if folder then
        for _,v in pairs(folder:GetChildren()) do
            if v:IsA("Sound") then
                v.Parent = global
            end
        end
    else
        error("Cindering's BGM error: Your global background music folder could not be found! You may have deleted/renamed the original folder. It should be named: "..name1)
        return
    end
end

if settings.UseGlobalBackgroundMusic == true and #global:GetChildren() == 0 then
    warn("Cindering's BGM warning: Your global background music folder is completely empty; no music will be played from there.")
end
if settings.UseMusicZones == true and #zones:GetChildren() == 0 then
    warn("Cindering's BGM warning: Your background music zones folder is completely empty; no music will be played from there.")
end

music.Name = "MusicFolder"
music.Parent = container

local count = 0
function recurse(instance)
    for _,v in pairs(instance:GetChildren()) do
        count = count + 1
        recurse(v)
    end
end
recurse(music)
local val = Instance.new("IntValue",container)
val.Name = "ObjectCount"
val.Value = count

container.Parent = game.ReplicatedStorage

script.Parent:Destroy()
0
This's someone else's script... TheeDeathCaster 2368 — 6y
0
Yes but I am wondering what I have to add or change to create a loop PrincessPaige12345 -3 — 6y
0
What's wrong with using someone else's script? I think the point is that if you're just doing something specific such as shorten the loop, 78 lines of code, especially without any explanations as to how the other lines relate to your question may be a bit too much. Houlardy642 28 — 6y

Closed as Not Constructive by TheeDeathCaster, theCJarmy7, and xAtom_ik

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

You can add a for do loop where you want it to loop

for i = 1, 10 do --the ten is the amount of times you want something to repeat
    --stuff
end
Ad