Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How so I call for an audio to play all the way through?

Asked by 9 days ago

Hello! I have a music playlist local script inside StarterGUI. Everything works perfectly fine, but I was wondering how to make the songs play all the way through instead of having to add a wait(130). I've noticed that some of the songs cut off either too early or too late with this wait, so I really wanted to just make it play until the end. Any help would be greatly appreciated!!

This is the original script

song1 = "http://www.roblox.com/asset/?id=4872114478" 
song2 = "http://www.roblox.com/asset/?id=423031173"
song3 = "http://www.roblox.com/asset/?id=4700827910"

local music = Instance.new("Sound") 
music.Archivable = true 
local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local songplaying = playergui.PromGui.BigFrame.Songplaying

music.Parent = script.Parent 
music.Pitch = 1 
music.Volume = 1 
music.Looped = false
music.Name = "Player"


while (true) do
    --1--
wait(5)
print 'Playing Sound 1'
    music.SoundId = song1 
    songplaying.Text = "Playing: Goodnight n Say So - Mashup "
    music:play()
        wait(130)  --- instead of wait, it plays the full song until the end
    --2--
print 'Playing Sound 2'
    music.SoundId = song2
    songplaying.Text = "Playing: Doja Cat - Trauma"
    music:play()    
        wait(130)
    --3--
print 'Playing Sound 3'
    music.SoundId = song3
    songplaying.Text = "Playing: Doja cat - Cyber"
    music:play()
        wait(130)   
end

Here's my attempt at making the songs play all the way through

song1 = "http://www.roblox.com/asset/?id=4872114478" 
song2 = "http://www.roblox.com/asset/?id=423031173"
song3 = "http://www.roblox.com/asset/?id=4700827910"

local music = Instance.new("Sound") 
music.Archivable = true 
local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local songplaying = playergui.PromGui.BigFrame.Songplaying

local marketplaceService = game:GetService("MarketplaceService")

music.Parent = script.Parent 
music.Pitch = 1 
music.Volume = 1 
music.Looped = false
music.Name = "Player"


while (true) do
    --1--
wait(5)
print 'Playing Sound 1'
    music.SoundId = song1
    song1 = marketplaceService:GetProductInfo()
    music.Loaded:Wait()
    songplaying.Text = "Playing: Goodnight n Say So - Mashup "
    music:play()
    --2--
print 'Playing Sound 2'
    music.SoundId = song2
    song2 = marketplaceService:GetProductInfo()
    music.Loaded:Wait()
    songplaying.Text = "Playing: Doja Cat - Trauma"
    music:play()    

    --3--
print 'Playing Sound 3'
    music.SoundId = song3
    song3 = marketplaceService:GetProductInfo()
    music.Loaded:Wait()
    songplaying.Text = "Playing: Doja cat - Cyber"
    music:play()

end

1 answer

Log in to vote
0
Answered by
Pupppy44 458 Moderation Voter
9 days ago

You can use the Ended function.

sound:Play()
sound.Ended:Wait()
sound:Destroy()

From the Wiki. Check it here: https://developer.roblox.com/en-us/api-reference/event/Sound/Ended

0
Never knew there was an ended function lol 7zjh 74 — 9d
0
It's really useful, by the way if it works please mark it as answered Pupppy44 458 — 9d
Ad

Answer this question