Problem With Boss theme with Lyric

I’m making a boss fight with a lyric which the singer is the boss itself singing about the current situation (similiar to Roar of the Jungle Dragon)

I want to make sure the player know what the lyric is about by including the subtitle and I want the timing the text apepar to sync with the song
Is there a better way I can pinpoint the certain time in the song so i don’t have to use task.wait() which could cause an issue if the song isn’t loaded correctly and I have to adjust the timing myself

AFAIK, not really.

If you want to make sure that the lyrics start at the same time as the music, in the event that it didn’t load immediately, you could try listening to the TimePosition property of the sound object getting changed.

i.e.

local Sound = ...
Sound:GetPropertyChangedSignal("TimePosition"):Once(function()
	-- Start lyrics thing here
end)
Sound:Play()

If you don’t want to spam task.wait(), you can create an array of arrays, where it has the text and the time position that they start (and optionally the time that they end). Note that this method works better when doing sequences of words at once rather than doing individual words.

e.g.

local Lyrics = {
	{"I've been walki' these streets so long", 8.0, 12.0},
	{"Singing the same old songs", 12.5, 15.5},
	{"I know every crack in these dirty sidewalks of Broadway", 16.5, 22.5}
}

Then, you would loop through the array (continuing on from the previously provided code). In the code below, I did it by recursively calling a function but looping normally would also work:

local Sound = ...
Sound:GetPropertyChangedSignal("TimePosition"):Once(function()
	-- Start lyrics thing here
	local function UpdateLyrics(Index)
		local Info = Lyrics[Index]
	
		if not Info then return end -- End of lyrics

		local Text = Info[1]
		local StartTime = Info[2]
		local EndTime = Info[3]

		if StartTime > Sound.TimePosition then
			task.wait(StartTime - Sound.TimePosition)
		end

		-- DISPLAY LYRICS (Text)

		if EndTime > Sound.TimePosition then
			task.wait(EndTime - Sound.TimePosition)
		end
		
		-- HIDE LYRICS (Text)

		UpdateLyrics(Index + 1)
	end
	UpdateLyrics(1)
end)
Sound:Play()
1 Like