Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Is there a more efficient way to use wait()?

Asked by 8 years ago

For example, I use:

while true do wait() print("YOUR PLANE HAS BEEN HIJACKED HAHAHAHAHAHA") end

I heard there are more efficient ways to use this.

I heard of:

os.time

tick()

wait(time)

If there are more, let me know and explain.

I know what these are, but I am yet to find out how to use it to it's full potential!

Just asking, not a request

0
tick() gets the time since 12:00 AM 1-1-1970 from the server's time. os.time() gets the time since 12:00 AM 1-1-1970 but from GMT. Server wise, there is nothing faster than wait(). Client wise however, you can use game:GetService('RunService').RenderStepped:wait() and it will wait about half the time wait() will (THIS IS IN LOCALSCRIPT ONLY). M39a9am3R 3210 — 8y

3 answers

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago

What do you mean? When you want to pause, you wait. os.time and tick aren't meant to pause the thread, they just show you how much time has passed since a certain date. It's best to use os.time since it's not native to the ROBLOX server's time zone (ROBLOX has servers in different parts of the world). This is useful for getting difference in time.

t1 = os.time()
wait(2)
t2 = os.time()
print(t2 - t1)

wait is a function that returns 2 values, how long it waited and how long the game has been running. We could use that instead:

wait(5) --To let the game run for a while

elapsed, runtime = wait()
print(elapsed.."\n"..runtime) --\n is a line break, like pressing enter on the keyboard.

But really, if you just want to pause the game, you wait.

Ad
Log in to vote
1
Answered by 8 years ago

Well wait() is the fastest amount of time that your studio can process. You can edit this in your studio settings. However, you have to be careful as Lua itself can only be processed so fast. If you want to find out how fast you can make a wait without getting into trouble, I would use RunService:

local RunService = game:GetService('RunService')
local LoopCount = 5
local Count = 0

RunService.Heartbeat:connect(function(Step)
    if Count < LoopCount then
        Count = Count + 1
        print("Time between each loop: "..Step)
    end
end)

But to avoid all this inconvenience, you can say that it is about 1/30 of a second. A little less than a frame. So you can say wait(1/30) for about as fast as you can go.

But tick() is the local time after the UNIX epoch. os.Time is the time of the server. Both will differ depending on the timezone. They just show what time it is. wait() is a set amount of time for the script to wait before continuing.

0
There's also the RenderStepped event which fires every render frame, or 1/60 of a second. funyun 958 — 8y
0
True, but it is better to run that locally as to not strain the server. BobserLuck 367 — 8y
0
RenderStepped works only on the client - its not an option for server scrips. JasonTheOwner 391 — 8y
Log in to vote
-1
Answered by
iSvenDerp 233 Moderation Voter
8 years ago

Hi..I'm on mobile so I can't help that mucb right now but I'll how another way it can simplify it easier.

Example = 5--this is a variable 

--code here
Wait(Example) 

There we made a string! Hope this helped let me know of it did

0
Thanks, but I would also like to know what tick() and os.time is. laughablehaha 494 — 8y
0
Oh ok my bad I just thought u wanted one iSvenDerp 233 — 8y

Answer this question