How can i sync music for all players

Hi! I’m doing vibe game. Theres playlist in my game and musics playing randomly at server script. Everything is okay but when new players joins to server they hearing musics at different TimePosition.

How can i sync musics for all players.
I just want to do players hear music from same TimePosition

4 Likes

Are you playing the Sound from server, or does client handle it?

1 Like

play music on server side : ) .

3 Likes

play the sounds on the server side . Use RemoteEvent if you are in localscript

Music playing at from Server not Client

This is the playlist system, plays music for all players but time positions different:

while true do
	wait()
	if CanStart == true then
		Values.Timer.Value = 2
		repeat wait(1) Values.Timer.Value -= 1 until Values.Timer.Value <= 0
		local RandomSong = math.random(1, 2)
		if RandomSong == 1 then
			SelectedSong = Songs.CrabRave
			SelectedSong:Play()
			Values.PlayingTrack.Value = SelectedSong.Name
		elseif RandomSong == 2 then
			SelectedSong = Songs.DancinKrono
			SelectedSong:Play()
			Values.PlayingTrack.Value = SelectedSong.Name
		end
		Values.Timer.Value = SelectedSong.TimeLength
		repeat wait(1) Values.Timer.Value -= 1 until Values.Timer.Value <= 0
		print("Music ended")
	end
end

Crazy error but I can see it. You do have TimePosition and someone else hearing it … Maybe try finding where they are and setting the new player to that TimePosition.

1 Like

Music playing for everybody but different timepositions.

Example:
-When music plays and new player join to game, music playing at different timeposition so player hearing different to other players.

Ya but you know where the player that is hearing it is at timeposition wise … You can get that info.
Then make the new players timeposition match that.

Perhaps handle the playback of the music on client. Use remoteevents and their method :FireAllClients(...). Put music ID and timeposition as the arguments. Then recieve this on client, and the client will play music on their side.

This is just what I’m talking about … And I’m also guessing it may work. Worth a test or two. Figure this should work-ish. I’m sure it will be just a bit off, but within an acceptable range.

Try this:

-- Define a function to synchronize the playback position for new players
local function syncPlaybackPosition(player)
	-- Get the current playback position of the selected song
	local currentPlaybackPosition = SelectedSong.PlaybackPosition
	
	-- Broadcast the current playback position to the newly joined player
	-- You may need to adapt this to match your game's communication system
	-- For example, you can use RemoteEvents or RemoteFunctions to send data to the player
	-- Replace "SyncPlaybackPosition" with the appropriate event or function name
	-- and pass the current playback position as an argument
	-- For example: game.ReplicatedStorage.SyncPlaybackPosition:FireClient(player, currentPlaybackPosition)
end

while true do
	wait()
	if CanStart == true then
		Values.Timer.Value = 2
		repeat wait(1) Values.Timer.Value -= 1 until Values.Timer.Value <= 0
		
		local RandomSong = math.random(1, 2)
		local SelectedSong
		local SelectedSongName
		
		if RandomSong == 1 then
			SelectedSong = Songs.CrabRave
			SelectedSongName = "Crab Rave"
		elseif RandomSong == 2 then
			SelectedSong = Songs.DancinKrono
			SelectedSongName = "Dancin Krono"
		end
		
		SelectedSong:Play()
		Values.PlayingTrack.Value = SelectedSongName
		
		local songLength = SelectedSong.TimeLength
		
		-- Wait for the song to finish playing
		wait(songLength)
		
		SelectedSong:Stop()
		
		-- Synchronize playback position for all players
		for _, player in ipairs(game.Players:GetPlayers()) do
			syncPlaybackPosition(player)
		end
		
		print("Music ended")
	end
end

Probably this script will be only sync when music starts but i’ll try this

Just make them go to the raining tacos room till the next song starts …

Also sometimes dancing animations not playing at others do you know why?

Just started working with animations myself. You probably know more than me about it.