Code Audio Issue

song:GetPropertyChangedSignal("TimePosition"):Connect(function()
    local length = song.TimeLength
    local CurrentPosition = song.TimePosition
    local Step1 = length - CurrentPosition
    local Step2 = Step1 / length
    for i,v in pairs(game.Players:GetPlayers()) do
        local musicbar = v.PlayerGui.NewGui.Lobby.Music
        musicbar.Bar.Size = UDim2.new(Step2, 0,0.548, 0)
    end
end)

hey guys I’m trying to make a sound bar however the code doesnt even fire. Is time position broken or something? how do i tell where they are in the song without it

The time position property doesn’t call the Changed event because that would be very laggy. Try just using a loop to update your sound bar!

while task.wait() do
	if song.IsPlaying then
		local length = song.TimeLength
		local CurrentPosition = song.TimePosition
		local Step1 = length - CurrentPosition
		local Step2 = Step1 / length
		for i, v in pairs(game.Players:GetPlayers()) do
			local musicbar = v.PlayerGui.NewGui.Lobby.Music
			musicbar.Bar.Size = UDim2.new(Step2, 0,0.548, 0)
		end
	end
end
local function lerp(a, b, t)
	return a + (b - a) * t
end

local function change()
	game:GetService("RunService").Heartbeat:Connect(function ()
		local completionDecimal = song.TimePosition/song.TimeLength
		local barLength = lerp(0, 211, completionDecimal)
		game.Players.LocalPlayer.PlayerGui.NewGui.Lobby.Music.Bar.Size = UDim2.fromOffset(barLength,7)
	end)
end

hey i already did a bunch and i have another issue right now. I found a post to get to forumla to calculate the size of the bar however it only works on offset (Which is hella gay) how do i do it but with scale because offset SUCKS

Why don’t you use the ‘completionDecimal’ variable as the scale directly…?

I don’t know what that means I don’t work with offset I just know I divided the timeposition by the length which seems to only give me an offset answer.

The completionDecimal variable will most likely be a number between 0 and 1. So just use that as the scale for the size of your soundbar. Something like this:

Bar.Size = UDim2.new(completionDecimal,0,1,0)

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

When you use the lerp function, then you get an ‘offset’ answer because it’s in pixels.

1 Like

Imagine literally doing extra code just to be gay and make your gui offset. Some developers just want to watch the world burn. Thanks it worked btw

Developers who post solutions on common issues:
“I like offset because it gets me off knowing that I’m giving people an answer that is gay”

Sometimes offset can be helpful! It just depends on what you’re making.

There is no use for offset. It should be removed.