How to make a seconds counting system in RenderStepped?

So I want to make seconds increasing counter in renderstepped function how do I go about doing that?

eg

RunService.RenderStepped:Connect(function()
end)

Why?

That’s such an odd thing to want to do. There is most likely a better alternative.

Because I need it for my calculations

That doesn’t make any sense and you haven’t explained anything, so I can’t advise you on a better and more proper solution.

So I’ll give you a solution that fits what you asked for but that I would never use because it’s a waste of valuable efficiency.

local timeConsumed = 0;
rs.RenderStepped:Connect(function(deltaStep)
	timeConsumed += deltaStep
	if (timeConsumed >= 1) then
		print("One second has passed")
		timeConsumed = 0;
	end
end)
1 Like

I would use os.clock() as this function returns the amount of CPU time, down to the microsecond. Here is an example:

local startTime = os.clock()
RunService.RenderStepped:Connect(function() 
    local displayTime = os.clock() - startTime
    print(displayTime) 
end)

Hope this helps!

1 Like