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

What's the difference between using :Wait() and wait() in this scenario?

Asked by
Sorukan 240 Moderation Voter
4 years ago
Edited 4 years ago

I read somewhere that using :Wait() along with an event would significantly improve performance compared to just using wait(). I'm wondering if the line of codes that i wrote has any difference and which one is more practical?

First code

local number = 0

spawn(function()
    repeat wait() until number == 10
    print('Ten!')
end)

for i = 1,10 do
    wait(1)
    number = number + 1
    print(number)
end

Second code

local runService = game:GetService('RunService')

local number = 0

spawn(function()
    repeat runService.Stepped:Wait() until number == 10
    print('Ten!')
end)

for i = 1,10 do
    wait(1)
    number = number + 1
    print(number)
end
1
:Wait() is a method of RBXScriptSignal. It is a yield function, meaning it will pause the current Lua thread until a response is returned from the event. Ziffixture 6913 — 4y

1 answer

Log in to vote
1
Answered by
kisty1 111
4 years ago

wait() will try to wait for at least 1/30 seconds but it can wait longer if the game is lagging, whereas Stepped:Wait() will wait exactly a frame You should use Stepped:Wait() over wait() if you can

0
It will regulate the load-time between the frame-rates of different devices. Similar effect to void Update {} from Unity Engine. Ziffixture 6913 — 4y
Ad

Answer this question