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

How would I make this music player work successfully?

I made this music player that works fine in studio but in the online game, it sometimes skips to a different song in the middle of another one that's playing, sometimes just stops in the middle of a song, or doesn't even play the songs at all. It is randomized and I am using a dictionary table in a module script.

local songList = require(game.ServerStorage.Songs)

local songTable = {}

for key, v in pairs(songList) do
	table.insert(songTable, key)
end

local songSwitchEvent = game.ReplicatedStorage.SongSwitchEvent

while true do
	
	wait(1)
	
	local randomSong = songTable[math.random(#songTable)]
	
	script.Parent.SoundId = "rbxassetid://"..randomSong
	
	local musicName = songList[randomSong]
	
	songSwitchEvent:FireAllClients(musicName)
	
	script.Parent:Play()
	
	script.Parent.Ended:Wait()
	
end

1 comment

0

Unfortunately I’m not too familiar with songs. I could check it out some time later but for checks try adding print statements too see if you can find what’s wrong. Sorry for not being any help right now. I’d you still need help don’t hesitate to contact me.

1 answer

local songList = require(game.ServerStorage.Songs)

local songTable = {}

for key, v in pairs(songList) do
    table.insert(songTable, key)
end

local songSwitchEvent = game.ReplicatedStorage.SongSwitchEvent

function playSound()

    local randomSong = songTable[math.random(#songTable)]

    script.Parent.SoundId = "rbxassetid://"..randomSong

    local musicName = songList[randomSong]

    songSwitchEvent:FireAllClients(musicName)

    script.Parent:Play()

    script.Parent.Ended:Connect(playSound) --When song ends, calls the function again

end
playSound()

1 comment

0

Still doesn't play some songs and randomly skips

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