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

So how does the Sound event Ended work? [Not answered]...

Asked by 6 years ago
Edited 6 years ago
--Variables
Song = script.Parent.Song
SongName = script.Parent.BottomSection.SongName
Album = script.parent.BottomSection.AlbumCover
local ContentProvider = game:GetService("ContentProvider")
times = script.Parent.BottomSection.Length

Music = {
    {
        ['song'] = 'Bryson Tiller - Been That Way',
        ['artist'] = 'Bryson Tille',
        ['itemId'] = 'rbxassetid://313095574',
        ['length'] = 50
    },
    {
        ['song'] = 'Drake - God\'s Plan',
        ['artist'] = 'Drake',
        ['itemId'] = 'rbxassetid://1375384985',
        ['length'] = 50
    },
    {
        ['song'] = 'Bryson Tiller - You Got It',
        ['artist'] = 'Brsyon Tiller',
        ['itemId'] = 'rbxassetid://977685900',
        ['length'] = 50
    }
}


local getRandomSongId = function()
    return Music[math.random(1,#Music)]["itemId"]
end

Song.SoundId = getRandomSongId()

for _,v in pairs(Music)do
    if
        v.itemId == Song.SoundId then
        print("Found the correct array")
        SongName.Text = v.song
    end
end




--time length
while true do
times.Text = Song.TimePosition
wait(0.00000009)
end


Song.Ended:connect(function()
    print("hi")         --This part right here. When the song ends, nothing actually prints.
end)

So I'm trying to use the Ended event. For some reason, when the song actually ends, it doesn't print anything and nothing happens. Why is this? Is the ended event broken? Am I using it wrong?

EDIT: Someone gave me answer but the event doesn't work. I was having a dumb moment using the event but when I use it properly, it still doesn't work? I have a play button for the music to actually play. That's in another script. Can that be a problem?

0
Another problem might be on line 37 your if statement is on a different line then what your checking. Just move the v.itemId == Song.SoundId then up 1 line zblox164 531 — 5y
0
I know this is late...like very late zblox164 531 — 5y
0
Change connect to Connect maybe that will work. zblox164 531 — 5y
0
This post is so old lol. I've learned about the Song.Ended. Sharkeedub 179 — 5y

1 answer

Log in to vote
1
Answered by
zblox164 531 Moderation Voter
6 years ago
Edited 5 years ago

Your using events wrong. You don't use an if statement you need to connect a function to the event for it to work.

Example:

 Song.Ended:Connect(function(parameters) -- Connects the event to a function
    print("Song has ended") -- What happens when the event has been called
end)  -- Ends the function. Notice the parenthesis at the end "end)".   

You could also write the code like this:

function soundEnded(parameters) -- Creates a function
    print("Song has ended") -- What happens when the function has been called
end -- Ends the function

Song.Ended:Connect(soundEnded) -- Calls the function

-- You could call the function like this

Song.Ended:Connect(function()
    soundEnded()
end)

You can put code inside of the function for what you want to happen. This goes for all events. Hope this helps

You can check this link out for more details:

http://wiki.roblox.com/index.php?title=RBXScriptSignal

Ad

Answer this question