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

[GOT IT WORKING] Is there a way to make music loop until a break in the middle?

Asked by 3 years ago
Edited 3 years ago

Note: I solved it by stop being dumb and turning my Roblox studio volume up in my volume mixer so it's working

Hello! This might be a little picky, but I think that Roblox Lua can do this so I'm asking here before giving up.

My idea is to have it so quiet music plays in the background at .2 volume, until it abruptly stops after 5 minutes, and then starts again 2 minutes later. If you can somehow manage the impossible and make it only play to players who touch a certain brick I would be amazed and so thankful (but that might be basically impossible, so I'm not getting my hopes up)

And a small side note, the code I have doesn't work, it does the first print but goes blank after that

Here's where I got

I made a folder with the sound and the script, and the script says such:

for i =1, 1000 do --this is the repeater that repeats this entire script 1,000 times (or I wish it was)
    local Music = game.Workspace.Music.Background

    while Music.Volume < .2 do
        wait(10)
    print('Music is starting')
        Music.Volume = Music.Volume + .01
        wait(5)
    end --I believe this should make is so that it will add .01 volume to the music until it is at .2 volume, basically making it fade in?
    print("Music is at full volume!")

    local Timer = 0
    while Timer < 300 do
        print("Seconds remaining: " .. Timer)
        wait(1)
        Timer = Timer + 1
        if Timer == 300 then
            Music:Stop()
            wait(120) --this is supposed to be where the timer that stops the music in 5 minutes and then starts it back up in 2
end
end
end

This might be an overly complicated version, but it's what mess of code I could stitch together. Since the song is not exactly 5 minutes long, this is the best I could try (Unsurprisingly, it prints that the music is starting and then nothing happens).

If the fading simply does not work or Roblox has an easier way of doing that I am completely okay with the way you do it, I'm going for function over it looking like code lol

Thank you for reading

0
If the sound volume starts at 0 until it fades into 0.2, it will take about 5 minutes for the first while loop to finish. This could be why the second print never prints. (0.2/0.01) * 15 seconds per loop Sparks 534 — 3y
0
Also to have the sound play for certain people who touch a part, you will need to utilize a RemoteEvent:FireClient() invokation to the player that touched the part, so that they can play the sound. If the sound is played on the client then it won't replicate. Sparks 534 — 3y
0
Yeah, I was messing around with that and I couldn't figure out how to make the Remotes work. Might tackle it another time, I don't know. Thanks for the math! PixelatedCube64 28 — 3y

Answer this question