Help with Music Player

I’ve made this music player script in a while although there has been a glitch on it that really triggers me.

When it changes to a new song, the new song instead of playing from the beginning, starts playing from the middle of the song. Please help me with this, any kind of help is welcome.

local currentSound = game.ReplicatedStorage:WaitForChild("CurrentMusic")
local songs = script:GetChildren()

while true do
	for i, song in pairs(songs) do
		local picked = songs[math.random(1,#songs)]
		local id = picked.Value
		currentSound.SoundId = id
		currentSound.TimePosition = 0
		wait(1)
		currentSound:Play()
		wait(currentSound.TimeLength)
	end
end

Try to stop the sound after the wait. Not sure if it will work because I have not tested it but it might I guess. For example:

	for i, song in pairs(songs) do
		local picked = songs[math.random(1,#songs)]
		local id = picked.Value
		currentSound.SoundId = id
		currentSound.TimePosition = 0
		wait(1)
		currentSound:Play()
		wait(currentSound.TimeLength)
		currentSound:Stop()
	end
end
1 Like

Thank you so much, this worked!

Although, I had to remove the wait(1) before currentSound:Play()

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.