PLEASE READ BELOW BEFORE COMMENTING
Hi there, I have a song playlist script which loops through a list of songs and plays them randomly. I’ve been sticking with using a local script of that playlist script since if I used a serverscripts, stuff bugs out and functions don’t connect properly in order. What I want to achieve, is to somehow always send out info of a song playing on a playlist on a serverscript including the time and position, then have the info read on a local script and play the info from that serverscript (for example what song should be playing).
Of course, I could easily fix this and change it to a serverscript, but the issue is, is that because it’s on the server, the loops and functions (for example how it transition to the next song) somehow mess up its order even in a loop, and then breaks the entire script and is too hard to explain what the bug is. However, the main goal is achieving as what said in the title, and not how to fix this bug.
Ever since I had it as a local script, everything works perfectly fine excepts the songs that are playing aren’t in sync with other players.
Script (originally a local script located in starterplayerscripts):
local MPS = game:GetService("MarketplaceService")
local currentTrack = game.ReplicatedStorage.CurrentTrack
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound
music = {
"rbxassetid://3044286747",
"rbxassetid://1256391355",
"rbxassetid://5480102561",
"rbxassetid://5024527209",
"rbxassetid://870242868",
"rbxassetid://1112109949",
"rbxassetid://6303331764",
"rbxassetid://2206587324",
"rbxassetid://5987864893",
"rbxassetid://534429024",
"rbxassetid://4551177864",
"rbxassetid://664277618",
"rbxassetid://3011342543",
"rbxassetid://3523361267",
"rbxassetid://3616424949";
}
while true do
if not musicplayer.IsPlaying then
local RandomSong = music[math.random(1, #music)]
local SongID = string.match(RandomSong, "%d+")
local SongInfo = MPS:GetProductInfo(SongID)
musicplayer.SoundId = RandomSong
musicplayer:Play()
currentTrack.Value = "..." -- displays the song playing in a music player gui
currentTrack.Value = SongInfo.Name -- just for displaying current song playing
musicplayer.Ended:Wait()
game:GetService("RunService"):UnbindFromRenderStep("CurrentTrack")
end
end