Making a music bar?

Okay so, I’ve made a music system that displays the name of the song etc, now I want it to show a bar to show the song progress. I’ve tried searching a few different websites and stuff on how to do this, and I’ve had no luck. Here’s the code so far:

local sound = game.Workspace.SongPlay
local progress = script.Parent.Main.ProgressBar.Progress
local songName = script.Parent.Main.SongName

local songs = {
	5060369688,
	4954877483,
	1518997709,
	867775492
}

while wait() do
	sound:Stop()
	progress.Size = UDim2.new(0.022, 0,1, 0)
	if not sound.IsPlaying then
		local chosenSong = songs[math.random(1,#songs)]
		local asset = game.MarketplaceService:GetProductInfo(chosenSong)
		
		local timee = sound.TimeLength
		
		sound.SoundId = "rbxassetid://"..chosenSong
		sound:Play()
		songName.Text = "Playing ; "..asset.Name
		wait(0.5)
		progress:TweenSize(UDim2.new(1, 0,1, 0),"Out","Sine",timee)
		wait(sound.TimeLength)
	end
end

Any help will be greatly appreciated.

4 Likes

You can use Sound.TimeLength to get the length of the song and then make it fit with your gui at where the sound is currently by using Sound.TimePosition. I believe you’ll have to do some math around this to fit with your gui.

1 Like

Assuming your bar moves horizontally, this should work:

local bar = script.Parent
local sound = game.Workspace.Music

while wait() do
bar.Size = UDim2.new(sound.TimePosition / sound.TimeLength, 0, 1, 0)
end
2 Likes