so then how did the psx dev do it?
psx? What is that? Sorry if im dumb ;-;
short for pet simulator x
(extra owdoawhdoahdo)
Ohhhh right, i haven’t played it in so long, but i told you that task.wait gives you nearly a millisecond
Using tick(), which was suggested in a reply above the message you sent
Maybe try using os.difftime.
@zionqyl and @good1005 but that script still waits while task.wait() do
, so it steps every .016 seconds, not in milliseconds.
I think task.wait() would work just fine if they are going for the same result of what the video had ( so for example it would say “3.5 seconds left” )
Would this be actually a millisecond or close to it
The short answer is that it’s not possible to get a millisecond countdown. The shortest wait is task.wait which, as others have stated, has a delay of about 0.016 or 16 milliseconds. What you can do is this:
local seconds = 10
while seconds >= 0 do
script.Parent.Text = math.round(seconds * 10) / 10
seconds -= task.wait()
end
EXPLAINATION
The seconds holds the count total wait time. task.wait()
returns the actual time it waited, so that value is subtracted from seconds each time the loop iterates. I put the text before the wait because the loop exit condition is that seconds is >= 0. When seconds goes negative, the loop exits. The text line multiplies the seconds by 10, rounds the result, then divides it by 10 to get a 0.1 second countdown. You don’t want to go much more than that because of network latency.
Very close to it, and the closest you can get just like @msix29 and @Maelstorm_1973 (also many others) just said
How do I set my own amount of seconds and how do I stop the counter
for Index = 10, 0, -0.1 do
script.Parent.Text = '⏳ '..Index
if Index == 0 then
script.Parent.Text = '✅ Complete!'
break
end
task.wait(0.1)
end
This would be the most condensed code for this you’ll probably get. (Don’t reply just to challenge that statement, I’m not looking for that.)
There is no delay so it will finish in less than a millisecond/instantly.
I just realized that, and I fixed it.
task.wait() cant go under 0.16 seconds, i did mention it before, there is no difference between what you did and what everybody said.
You should generally avoid while loops as much as possible, unless necessary. This would be a better practice as it avoids using spawn function(s), to prevent unnecessary threads that can be avoided, (utilizing my code above).
Now hey, you can do as you please with while loops and I’m not one to judge that, however, this is a better alternative to a while loop to use as a countdown, especially in this situation.
We are taking about the delay and not how we implement it, so no need to care about this one now.
Well seeing as my delay is the same as everyone else’s, than what’s the big deal? If I’m using the best practice, why would you argue about that? You said: there is no difference between what you did and what everybody said.
But the difference was what I stated above. Everyone is using while loops, while I’m using a for loop. (Which is a better practice in this situation, as we don’t need to loop infinitely, but instead, we will only loop for the amount of time necessary.)
As far as I can see, you’ve provided 0 scripts to add to this thread, so you have no place to be judging my code, especially when you said task.wait()
was better, yourself. Now we’re done arguing about this, but if you have any questions, refer to the API Docs on loops.
I’m not one to get involved in arguments, but for what it’s worth, I don’t see anything wrong with your code. It fulfills the OP requirements. My code is more precise since it actually uses the return value from task.wait() to subtract from seconds. Since task.wait() always returns the actual amount of time that it waited, there is no danger of it going into an infinite loop.
Besides, on a related note, most operating system kernels program PIT (Programmable Interval Timer) channel 0 to provide an output frequency of 1000 Hz (1 kHz, or pulse at 1,000 times per second). Timer channel 0 is hardwired to PIC (Programmable Interrupt Controller) channel 0 (INT 0) which is the highest priority hardware interrupt outside of NMI (Non-Maskable Interrupt) and RESET. The INT 0 ISR (Interrupt Service Routine) vectors into kernel space and eventually reaches the scheduler which determines the next thread to run. So there is no way to get a millisecond timer unless one gets it from the operating system kernel itself. Low level and bare metal coding are my specialties as a system software engineer.