Help making my time a string

Hi developers!

Sorry about the confusing title. I’ll explain a bit more here:

I’m making this corny “Survival the Killer”-esque game, and I’m having a round timer be implemented. A LocalScript is currently running all of the base game values. Essentially, a timer is being counted down and a value is set to the current time. My script is updating the timer textLabel to be the time, and I use a format function to make it set into an actual time.

My issue arises when I try to set my text to the time. I have it printed for mine and your convenience:


Error in question

Here’s my code that it’s causing issues at:

image
why doesnt this work :rage:

I’ve tried tostring() but apparently the format isn’t an acceptable argument, so it also errors. Any help would be greatly appreciated, as I say in all of my posts.

Thanks!

2 Likes

Would I be able to see the format function please? The code seems to be fine, but it’s probably something that’s within the format function that causes the error.

1 Like

image
Here you are!

Edit: Removing the toNum variable doesn’t affect the function either. :sob:

1 Like

This converts the number into a format like this: 00:00 correct?
If so you can use this code to format it the same way:

local function ToString(x: number)
	return string.format("%02i", x :: number) :: string
end

local function ToFormat(x: number)
	local minutes: number = (x :: number - x :: number % 60 :: number) / 60 :: number
	x -= minutes :: number * 60 :: number
	
	return ToString(minutes :: number) .. ":" .. ToString(x :: number)
end

You can do:

timeLeft:GetPropertyChangedSignal("Value"):Connect(function()
	timeLabel.Text = ToFormat(timeLeft.Value)
end)

Hope this helps

1 Like

Works amazingly, thank you!!

i hate the limit grahhhh!!!

1 Like

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