Frame wont scale correctly

Trying to make an audio progress bar, but it wont change at all

Tried looking around the dev forum, but ive had no luck finding something that was close to my issue, as most opted for tweening, or were based on the wrong values.

task.spawn(function()
	while true do
		local SoundLength = AudioPlayer.TimeLength
		local CurrentPos = AudioPlayer.TimePosition
		local Percentage = CurrentPos / SoundLength / 100
		local Clip = math.floor(Percentage / 0.1) * 0.1
		print(Clip)
		ProgressBar.Size = UDim2.new(Clip,0,1,0)
		task.wait(.01)
	end
end)

AudioPlayer is a Sound object

ProgressBar is a frame in another frame, size being {1, 0},{1, 0}
Im trying to mainly edit the first one, on a range from 0 - just starting, to 1 - finished

after removing some lines, seems it doesnt run at all, there are no loops before it, and even making it a normal loop does nothing

any prints before it dont run, but functions do

Probably weird Roblox jank, removing the function call before it lets it run, adding a print just spams 0, even when music is playing

This value will always be between 0 and 0.01, you need to remove the / 100!

Instead of doing while task.wait(0.1) do,
Do this:
local RS = game:GetService(“RunService”)
RS.RenderStepped:Connect(function())

Can you show us the property of your progressbar?

This should fix it:

game:GetService("RunService").RenderStepped:Connect(function()
	local length = AudioPlayer.TimeLength
	if length == 0 then return end
	local pos = AudioPlayer.TimePosition
	ProgressBar.Size = UDim2.new(pos/length,0,1,0)
end)

This worked perfectly, cant believe i was this dumb lol, still has some more work to do, but it is all easy, thanks :+1:

1 Like

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