How to make a working timer for my rhythm game

So . . . I tried to search this up and had no luck. How would I make a timer for my rhythm game.

How would I do a timer that is in sync with the audio file that is playing in the background? I want to put it on GUI and I have that set up.

I want to make a timer in the format “TIMENOW/ENTIRETIME”

For example, if I had been playing for a minute and the song was three minutes long, it would look like “1:00/3:00”

Thanks DevForum!

Each Sound instance has a TimeLength and TimePosition property. The first specifies how long the sound file is in seconds, and the second at what second the sound is while being played.

Of course, you’d have to format the timer to turn from just seconds to seconds/minutes.

^ Just get rid of the hours and this should work fine.

So just use that and just get the time of the song that’s playing? is it possible to get the time of a song?

yes it is

Then I suppose all I need to do is that, and just put that on my timer label since the song IS already playing

mhm thats all you need to do!

1 Like
local timerLabel = script.Parent

local runserv = game:GetService("RunService")

runserv.Heartbeat:Connect(function()
	local song = game.ReplicatedStorage.chosenSong.Value	
	local timer = (song.TimePosition .. "/" .. song.TimeLength)
	timerLabel.Text = timer
end)

It’s not seeming to change for some reason? Is it possibly because I put the chosenSong value in ReplicatedStorage?

wait what chosenSong.Value? you need the actual sound Instance for that property not just a number value. or is that an object value?

It is an object value, it’s so that when I use teleport service players can pick the song and it will choose the correct object value.

Edit: It’s working, I moved it out of the workspace, now I just need to round it.

EDIT 2: It works well, but the numbers are glitching a little.

maybe try using .changed then? maybe that would work?

local timerLabel = script.Parent

local runserv = game:GetService("RunService")

local songval = game.ReplicatedStorage.chosenSong
songval.Changed:Connect(function()
	local song = game.ReplicatedStorage.chosenSong.Value
	song.Changed:Connect(function()
		local timer = (song.TimePosition .. "/" .. song.TimeLength)
		timerLabel.Text = timer
	end)
end)

or maybe just use a sound instance and NOT a value. can you also tell me where the song is? and if it even is playing? on the client

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.