make me a localscript that i'll parent inside a textlabel. it should count the seconds…
- User
make me a localscript that i'll parent inside a textlabel. it should count the seconds and the first two digits of miliseconds
- Assistant
Sure, here's an example of how you can create a LocalScript that counts seconds and the first two digits of milliseconds. This script will be parented inside a TextLabel in Roblox's scripting environment.
lua-- Parent this script to a TextLabel local textLabel = script.Parent local startTime = tick() -- get the current time in seconds -- Function to format time in seconds and milliseconds local function formatTime(elapsedTime) local seconds = math.floor(elapsedTime) local milliseconds = math.floor((elapsedTime - seconds) * 100) return string.format("%d.%02d", seconds, milliseconds) end -- Main loop to update the TextLabel's text every frame game:GetService("RunService").RenderStepped:Connect(function() local currentTime = tick() -- get the current time in seconds local elapsedTime = currentTime - startTime -- calculate elapsed time textLabel.Text = formatTime(elapsedTime) end) - User
what if i want the seconds to be double-digits?
- Assistant
If you want the seconds to always be displayed as double-digits (i.e., "05" instead of "5"), you can adjust the formatting used in the
formatTimefunction. Below is the updated script to achieve this:lua - User
parented to the textlabel is also a loading bar, which is a frame. make it gradually increase
- Assistant