How to add text number every second via script


How to add +1 C in every second I want something to be like this…

local number = 1
"Temperature ,,number + 1,,°C",

This should look like this:
Temperature 1 °C (wait 1)
Temperature 2 °C (wait 1)
Temperature 3 °C (wait 1)
Temperature 4 °C (wait 1)
so on…

It isnt that hard.

local Number = 0

while task.wait(1) do -- Fires every 1 second
Example.Text = "Temperature "..Number.."°C" -- concats Text
Number += 1 -- Adds Number
end

1 Like

Sorry, I did not remember that thanks :slight_smile:

@DasKairo
@GTX_3
While loops are bad for performance, use a better alternative.

What better alternative?

repeat
until

for ex = num,num do
end

Also no.
RenderStepped is the way to go.

Why would you use RunService?

RenderStepped only works on the Client and RunService is only used to run stuff Pre or Post Frames

It can also still cause performance issues

RunService is the best for performance. That has been said way too many times.

no it does not, It literally another form of loop:

RunService.RenderStepped:Connect(function(DeltaTime)
  -- Fires in Code in Delta Time
end)

while true do
 RunService.RenderStepped:Wait() -- Yields code in Delta Time
end

1 Like

Actually in this case, it won’t matter much. RunService doesn’t create loops BTW, it just runs the functions every frame, it is not a loop.

Yes, in other words: A loop

Runs the same code every time until disconnected

While loops aren’t bad for performance and whoever says that is wrong. Loops are a normal part of programming and they have minimal overhead. It’s a single opcode. They’re just about the most efficient thing you can make and Roblox has created optimizations specifically for while loops to make it even better.

You’re definitely confused. RunService is event-driven programming, and considering it fires 60 times per second, it will tank performance if used for intensive tasks that take longer than 16 milliseconds. A regular loop can be configured to avoid that, thus enhancing performance.

2 Likes

Alright, thanks for the clarification.