Problem with Music Timer

So i made a Timer for my new vibe game but now if i use it it will always put a , after the seconds cause the song is longer then only one second and it will print this:
image
What is actually needs to say is 02:34

And this is my script that i made to make the timer work

Also if you don’t know what the local Sec, Min and ID is that are Values the ID is the id if the song so if the ID changed then the timer will be set to the next song time.

local Sec = script.Parent.Sec.Value
local Min = script.Parent.Min.Value

local TimeLenght = game.Workspace.Music.Sound.TimeLength
local ID = game.Workspace.Music.Sound.ID

Sec = TimeLenght
repeat
	Sec -= 60
	Min += 1
until Sec < 60
if Sec < 10 then
	script.Parent.Text = "0"..Min..":".."0"..Sec
else
	script.Parent.Text = "0"..Min..":"..Sec
end
ID.Changed:Connect(function()
	Sec = 0
	Min = 0
	wait()
	Sec = TimeLenght
	repeat
		Sec -= 60
		Min += 1
	until Sec < 60
	if Sec < 10 then
		script.Parent.Text = "0"..Min..":".."0"..Sec
	else
		script.Parent.Text = "0"..Min..":"..Sec
	end
end)

Also this is not a timer that moves it just need to say how long the song will be

2 Likes

So the only question i have is how to i delete all the .000 after the Value cause i don’t need them

Couldn’t you just use IntValues instead? Those don’t support decimals, while NumberValues do

I will try now i didn’t try that and i also didn’t know that and your my only hope now so i’m gonna try now.

From what I’m assuming, all of your variables are NumberValues or Numbers of some sort

Just change the Sec variable to a IntValue then I believe you should be all set, or you could also use the math.round() function to convert it that way

it didn’t work i changed the sec value to an intvalue
image

The only way I could think of is by splitting a string - I’m not amazing at lua.

local str = '02:34.728'
str:gsub('(.*).', function (time)
print(time) -- prints 02:34
end)

I can try that but idk where to put it cause also every song has an other value of time so the 02:34.728 will never work cause every song has an other value

Wait

You’re equaling the value to that, why though? It’d just result as returning back decimals

Could you try this?

local Sec = script.Parent.Sec.Value
local Min = script.Parent.Min.Value

local TimeLenght = game.Workspace.Music.Sound.TimeLength
local ID = game.Workspace.Music.Sound.ID

Sec = math.round(TimeLenght)
repeat
	Sec -= 60
	Min += 1
until Sec < 60
if Sec < 10 then
	script.Parent.Text = "0"..Min..":".."0"..Sec
else
	script.Parent.Text = "0"..Min..":"..Sec
end
ID.Changed:Connect(function()
	Sec = 0
	Min = 0
	wait()
	Sec = math.round(TimeLenght)
	repeat
		Sec -= 60
		Min += 1
	until Sec < 60
	if Sec < 10 then
		script.Parent.Text = "0"..Min..":".."0"..Sec
	else
		script.Parent.Text = "0"..Min..":"..Sec
	end
end)
2 Likes

Ye ty it worked nice work also can i ask you how you did it so i can understand it for the next time so i don’t need to post something else again?

You know rounding (That one Math subject?)

Yeah, basically math.round() converts the given number to the closest whole integer

Some examples:

local Decimal = 5.93
Decimal = math.round(Decimal)

print(Decimal) --Should print 6
local Decimal = 12.50
Decimal = math.round(Decimal)

print(Decimal) --Should print 13

Uh idk why but it is glitched now the value is below 60
image

Sometimes it works and sometimes it doesn’t

Oh ye i’m so dumb but ty for helping me

1 Like

Weird, maybe it’s something within your script? Could you just try doing Sec = 0 instead of Sec -= 60?

Ye i can but then it will not go down with the second so then it will be 10000 minutes so i don’t think that will work i think it’s something with the < and not the sec -= 60

But it is weird cause sometimes it does work

Idk why but it only works in roblox studio now that i see and i published it multiple times and i did shutdown the server

Also if you wanna test it you can here then you can see it doesn’t work: Game

Nvm it works now idk why it didn’t

srr for that it works now ty for helping me.