How can i make timecode in roblox

For my beams im trying to add a library of songs that are timecoded but idk how i would sync up flashes to points in the music does anyone know a way to do this?

You can use Sound.IsLoaded to wait for the sound to load, then play the music and the beams at the same time.

1 Like

but how would i know what point the song was at to know when to flash the beams etc

What do you mean exactly? If you want to see the position the sound is, use Sound.TimePosition, if you actually want to know which points the music goes loud/quiet for creating the beam order, you could record the Sound.PlaybackLoudness every frame in a RunServer.RenderStepped function, then see which points that value goes high/low and put a beam at that time, you could also use tick() to get the current time in seconds.

1 Like

so with this information how can i make it for example when sound.timepositon == 10 do whatever

Do you mean how would you code it so the beam would appear at time position 10?

1 Like

basically yes and it would need more than one idk if u know what i mean by beams but yes

local RunSerivce = game:GetService("RunService")

local Keyframes = {
	{TimePosition = 1, Played = false},
	{TimePosition = 3, Played = false},
	{TimePosition = 10, Played = false},
	{TimePosition = 15, Played = false},
}

local function playSound(Sound)
	Sound:Play()
	while Sound.IsLoaded == false do wait() end
	print("Sound loaded!")
	
	Sound.TimePosition = 0 -- // Just ot make sure it's synced
	
	while Sound.IsPlaying do
		
		for i,v in pairs(Keyframes) do
			if (v.Played == false) and (v.TimePosition <= Sound.TimePosition) then
				print("Keyframe at " .. tostring(v.TimePosition) .. " played at time " .. tostring(Sound.TimePosition))
				Keyframes[i].Played = true
			end
		end
		
		RunSerivce.Stepped:Wait()
	end
end
1 Like

so where do i put what i want it to do?

in Keyframes table, please read the whole script to understand it.
If you meant where do you do the beams and stuff, put that instead of the line where it prints Keyframe at...

1 Like

i know this way is short but i need it to do a lot more than just on and off i tried doing wait until but that didnt work

what do you mean by “on and off”, the keyframes will just run at the specified TimePosition, you can change the behaviour of them on your own inside this block

for i,v in pairs(Keyframes) do
			if (v.Played == false) and (v.TimePosition <= Sound.TimePosition) then
				
				-- // Put your code here
				
				Keyframes[i].Played = true
			end
		end
1 Like

I realy dont understand what to do i just need a loop that waits until for example 5 seconds then does something and then wait till 7 seconds then does something

local Time = 0

local function atTime(x)
	wait(x - Time)
	Time += x
end

atTime(5)

-- // Do something

atTime(10)

-- // Do something else
1 Like

does the time go off the position in the song or just waits?

This just waits, if you want to sync it with the song add this line before the first wait function
while Sound.IsLoaded == false do wait() end

1 Like

can i put decimals as the time?

yes you can, but remember to use atTime() function I gave instead of wait(), mine counts the time already elapsed

1 Like

Only the first one works then the rest just all happen at once

Can you show me the script you written?

1 Like