Music Player not working

Okay, Im making a music player. The problem is its just not playing. Sometimes it does and sometimes it doesn’t. Im not sure what is the problem but I have a hunch its the Sound.Ended however im not to sure please help me check my code if anything is wrong Im extremely confused.

local MarketPlaceService = game:GetService("MarketplaceService")
local currentSound = game.ReplicatedStorage:FindFirstChild("CurrentMusic")

local songs = script:GetChildren()
local TVs = game.Workspace.TVScreens:GetChildren()


local checkfirstid = 0
local checksecondid = 0
local checkthirdid = 0

while true do
	checkthirdid = checksecondid
	checksecondid = checkfirstid

	local que = math.random(1,#songs)

	local id = songs[que].Value
	print("Song: "..id)

	currentSound.SoundId = "rbxassetid://" ..id

	if id == checkfirstid or id == checksecondid or id == checkthirdid then
		currentSound.TimePosition = currentSound.TimeLength
		print("Detected Reused Song")
	end

	currentSound:Play()
	print("PlayingSong")

	currentSound.Loaded:Wait()

	local timelength = currentSound.TimeLength

	for i, model in pairs(TVs) do
		local songInfo = MarketPlaceService:GetProductInfo(id)
		model.Screen.SurfaceGui.Frame.MusicName.Text = songInfo.Name.." - "..id
	end

	currentSound.Ended:Wait()
	print("Song Ended")

	checkfirstid = id
end





can we see your output so we can know where it fails?

It fails at the Song Ended
image

use sound.Stopped instead of sound.Ended, this fires when its paused instead of your thing.

Unfortunately doesnt work. still shows the same result just like the picture above

Hmm, could it be because you placed currentSound.Loaded:Wait() after you played the sound?

remove currentsound.Loaded:Wait() because that is the only other thing that could be holding it up.

No song is heard its just stuck there.

Yes, the song is already playing which is why you don’t need to wait for the song to load anymore. Although if you would like to wait for it to load, you should put the currentSound.Loaded:Wait() before the line where you played the sound.

Nothing is heard but the music display is working but no music is heard

image
this line puts a text on the screen it works but no sound is heard this is after Sound:Play()

Hold up I think i might know why. Probably because im using replicated storage

Ok I am utterly confused on what to do.

So far all this does is play a random sound from the list and displays all the music on the screens?

Are you trying to make each of the TVScreens play their own music?

No the TVScreens are all the same they display the same music

For some reason it always sees the Playing property as true even though it’s false.

Scratch that I was testing wrong.
I was changing time position on the client lol.

Maybe ill just rewrite code in some other way

For me it works.
What is wrong about it’s behavior on your side?

Probably. Eh I’ll just remake the code in some other way thanks for helping

In case it helps try setting the TimePosition back to 0 before the :Play().