Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

anyone help MusicPlayer help?

I'm trying to make a music player but i cant detect if the sound stopped or ended, Although i did use the events Stopped and Ended but didnt work

Call me a bad scripter but i dont know if this is good enough for a music player.

local SoundIds = {
'http://www.roblox.com/asset/?id=359748862',
'http://www.roblox.com/asset/?id=319758951',
'http://www.roblox.com/asset/?id=130777688',
'http://www.roblox.com/asset/?id=243372213',
'http://www.roblox.com/asset/?id=340910520',
'http://www.roblox.com/asset/?id=228676342',

	
	
	
	
}
local Ended == false
while true do
if Ended == false then
local Music = Instance.new('Sound', game.Workspace)
Music.SoundId = SoundIds[math.random(1, #SoundIds)]
Music.Name = 'In-game_Music'
Music.Volume = 0
Music:Play()
for i = 0, 1, .1 do
Music.Volume = i
wait(.4)
end
Music.Stopped:connect(function()
Ended = true
for i = 1, 0, -.1 do
Music.Volume = i
wait()
end
repeat wait(.5) until Ended == true
if Ended == true then
wait(.5)
game:GetService('Debris'):AddItem(Music, 2)
end
end)
end
end

1 comment

0

Stopped and Ended functions only work with local scripts.

1 answer

✓ Accepted answer

All you need to do is

while true do
--insert and play sound
Music.Ended:wait() -- or alternatively Stopped. I don't know what you exactly want
wait(.5)
end

Also "Stopped and Ended functions(*events) only work with local scripts" is incorrect.

This discussion is preserved as it was. New answers, comments, and votes are closed.