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

How do make my music player not repeat songs without it breaking?

Sometimes when the song is supposed to change, the song just doesnt play. I am assuming this is from return function() and it tries to repeat the same song but I really dont know why it stops playing.

Music.Ended:Connect(function()
	VoteReady.Value = false
	wait(1)
	local Song = math.random(1,NumberOfSongs)
	local SongChosen = Songs:FindFirstChild(Song)
	if SongChosen then
		if SongChosen.Value == LastSong.Value then
			return function()
			end
		else
		Music.SoundId = "rbxassetid://"..SongChosen.Value
		LastSong.Value = SongChosen.Value
		local SongNameFound = SongNames:FindFirstChild(Song)
		if SongNameFound then
		SongName.Value = SongNameFound.Value
		else
			warn("Song name not found!")
		end
		Music.TimePosition = 0
		Music:Play()
		VoteReady.Value = true
		end
	else
		warn("Song not found!")
		return function()
		end
	end
end)

3 comments

0

sorry forgot to add that part

0

I don't know why listeners are returning a value here? roblox does not expect anything back from them, and why are you returning a function. When a return statement is reached, the function ends, so if line 8-9 is reached, everything else under it will not execute

0

idk, I mean i am try to make it so the if the script tries to play the same song again it redoes the function until it picks a diff song

1 answer

Using functions like isPlaying()

The real one is in the wiki but that's how you add a new layer to make it play. Bam!

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