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
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.
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.
-- 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