Why isn't this working?

I am currently trying to mess with my music player and make it tell you the progress of the current song playing, however this does not seem to work. The only error I am getting is the hoursprogress is nil, which is most likely why it is not working but I’m sure theres other errors here that I would get if it wasn’t nil.

I also don’t think my rounding is correct.

Any help is appreciated.

while true do
	wait(0.1)
	
	local unroundedhoursprogress = workspace:WaitForChild("MusicPlayer").TimePosition / 3600
	local unroundedhoursfinish = workspace:WaitForChild("MusicPlayer").TimeLength / 3600
	
	local hoursprogress = round(unroundedhoursprogress)
	local hoursfinish = round(unroundedhoursfinish)
	
	local unroundedminutesprogress = hoursprogress - unroundedhoursprogress * 60
	local unroundedminutesfinish = hoursfinish - unroundedhoursfinish * 60
	
	local minutesprogress = round(unroundedhoursprogress)
	local minutesfinish = round(unroundedhoursfinish)
	
	local unroundedsecondsprogress = minutesprogress - unroundedminutesprogress * 60
	local unroundedsecondsfinish = minutesfinish - unroundedminutesfinish * 60
	
	local secondsprogress = round(unroundedsecondsprogress)
	local secondsfinish = round(unroundedsecondsfinish)
	
	
	script.Parent.Text = tostring(minutesprogress)..":".. tostring(secondsprogress) "/".. tostring(minutesfinish)..":".. tostring(secondsfinish)
end

function round(num)
    return math.floor(num + 0.5)
end
1 Like

Is round a function you made earlier in this code?

What do you mean by this? 30ch

In round(unroundedhoursprogress) line did you create a function named round earlier in this code or this is the entire code?

The round is below the while true do function.

This is the full code.

You need to create the function before the loop.

I tried this, still the same error.

Actually the same error but for a different thing

image
This is line 26

I’m pretty sure math.floor rounds it for you. I don’t think you need to add the 0.5 at the end

1 Like

You forgot to add a concat operator between tostring(secondsprogress) and “/” in script.Parent.Text = tostring(minutesprogress)..":".. tostring(secondsprogress) "/".. tostring(minutesfinish)..":".. tostring(secondsfinish).

2 Likes

Thanks! This fixed the issue with nil. Now for some reason it’s not showing the minutes.

image

Nevermind, fixed the problem. :smile: Thanks everyone!