Deprecated
WEwait() has been deprecated, and should not be used for new work. It is currently impossible to create a reliable
wait()
function.
Hello! As you might all know, wait()
is un-reliable. Today, I will show you how to make it reliable with a function I created! I call it WEwait()!
1. Create the NumberValue
Add a NumberValue to the script that you want to use WEwait for.
Why can’t I just use `Instance.new(“NumberValue”)?
It will make the code take longer to process. We want it to be instant.
2. Makind the function
First you will want to start with
local function Wait(waitTime)
end
And you will want to pass the argument/parameter waitTime.
3. Creating the Wait function
Now that we have the function, it is super simple. All you got to do is add the line we will be using. It is using TweenService, since that was programmed a lot better than :wait()
.
local waitTween = game:GetService("TweenService"):Create(script.Value, TweenInfo.new(waitTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Value = 1})
4. Playing and catching when the tween was played
Now, all you got to do is add the 2 following lines:
waitTween:Play()
waitTween.Completed:Wait()
This will play the waiting tween, and detect when it is completed.
5. Returning
Now, all you got to do is return the value, so you can use it exactly like wait()!
return
6. Using in your code
Now that your function was created, you can simply replace wait()
with capital Wait()
if you already have come code using wait()
.
If you are creating new code, simply use Wait()
and pass the amount of time you want to wait for.
I just want the function.
local function Wait(waitTime)
local waitTween = game:GetService("TweenService"):Create(script.Value, TweenInfo.new(waitTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Value = 1})
waitTween:Play()
waitTween.Completed:Wait()
return
end
And you would use Wait()
and not wait()
.
JUST MAKE SURE YOU HAVE A NUMBERVALUE INSIDE OF THE SCRIPT YOU WANT TO USE THIS IN!
Is it possible to just use wait() instead of Wait()?
Yes, it is! All you got to do is rename the function to wait() instead of Wait()! However, I don’t recommend this, because Roblox can just release an update to wait() to make it always use the un-reliable wait(). Global Wait() is already deprecated, so you should have no problems.
Examples:
- I use this method inside of Bloxy Kart, inside of the stopwatch on Time Trials mode
- Making code faster
I hope this helps you! If you have any questions, feel free to reply!
Hope this helps you!