How to use wait() for less than 0.1 seconds

I’ve been wondering how to make wait() shorter than 0.1 seconds, it’s especially noticeable when trying to make any rotating part using Cframe, it’s forced to either rotate really slowly (making small rotations every time) or have a really jagged rotation (making a normal speed of rotation, but making the part rotate large amounts every time)

Any alternatives to Cframe rotation or ways to make the wait() shorter? everything helps :hidere:

If I understand correctly, If you are trying to get to get the cframe rotation faster/shorter wait time, it might be to your advantage to use the Runservice

Also I am pretty sure you can use wait for less than .1 , like for example wait(.0001)

6 Likes

You can use TweenService instead to rotate your part’s CFrame
No wait() or RunService is needed.

local TweenService = game:GetService("TweenService")
local Part = workspace.Part

local Goal = {}
Goal.CFrame = --Goal CFrame

local TweenInfo = TweenInfo.new(2) --2 seconds
local Tween = TweenService:Create(Part, TweenInfo, Goal)
Tween:Play()

Wiki: https://developer.roblox.com/en-us/api-reference/class

4 Likes

I’d suggest using Render Stepped, as it updates every frame. To do this, however, you’ll have to use it on the client as it is client specific, but with a remote event you should be fine. Check out the link posted by @Jaycbee05 for a better explanation on it!

PS: I believe wait()'s minimum yield time is 1/30’th of a second.

3 Likes

wait() 's default / minimum time is 0.02999 (approx. 0.03) (1)/30th of a second).
For an even shorter time, you can use RunSeevice.RenderStepped which fires every1/client’s fps of a second (local script).

if the player’s fps is 60, RenderStepped will run every 1)60th of a second

Sorry if it’s typed horribly - i’m typing on a mobile device

8 Likes

Thank you, this will definitely help with a little sweeper game I’ve been working on.

P.S. I tried putting like 50 zeroes in front of the 1 and nothing was changing

2 Likes

Three advisories:

  • Wait can only yield a minimum of ~1/30th of a second
  • Wait will never actually wait for the time you specify
  • DO NOT USE RENDERSTEPPED IF NOT FOR CAMERA UPDATES.

Lua is single-threaded and all your tasks must be ran through the thread scheduler. This is responsible for executing your tasks, yielding and all that sweet goodness. With wait, you’re asking your thread to pause for n amount of time, cool. When your thread is yielding though, the task scheduler moves on to execute other tasks. Therefore, available slots are taken up. Now your thread will spend extra time yielding because it needs to wait for an open slot to execute its task.

As for RunService, do not use RenderStepped if you aren’t running inexpensive operations such as updating the Camera. Use Heartbeat (after physics simulate) or Stepped (before then). These are each ran every frame and return a number, deltaTime, which describes how much time passed between each time the event was fired (or rather between each frame). Running code in RenderStepped can delay the execution of render ticks and hurt your game’s performance.

25 Likes