A function that allows you to wait in milliseconds

well try repasting my code and measure the speed

Uhh dude, not her module, my module.

Your module isn’t actually a wait module as it doesn’t yield the thread at all, so if you were to put it into a while true do it would crash studio( like it is doing to mine right now), you’d be better of not using it at all as there is no way for it to wait until a specified time has elapsed and no other scripts would run at the same time as the thread scheduler will keep running this thread until it crashes.

also I thought you were this post’s creator and you shouldn’t be plugging you’re own post in another person’s post

1 Like

To me it does. I can show proof later

Try to mess with the second argument, you’ll see a difference

10 times per second is easy - you can do that with task.wait(). Try doing it 200 times per second. It won’t be able to do it properly, since it’s still based on Heartbeat.

why do you keep saying heartbeat is still slow for terrain generation? are you doing this?

while true do
  for y=1,200, do
    for x=1,200 do
      --perlin code
      task.wait()
    end
  end
end

maybe instead of spamming wait() to “garbage collect” how about you decrease your space complexity to avoid running out of memory (or just turn off script timeout lol). How? well how about making it one loop, saves LOADS of ram usage. Also, please don’t tell me you are doing some crap like this

for y=1,200, do
    for x=1,200 do
       local perlinNode = Instance.new("Part")
       --[[
        perlin properties
        ]]
        perlinNode.Name = tostring(x).."."..tostring(y) -- uh oh
       perlinNode.Parent
      --perlin code
      task.wait()
    end
  end
while true do
  for y=1,200, do
    for x=1,200 do
      local perlinToModifyPosition = workspace[tostring(x).."."..tostring(y)] --kms with this datamodel overload
      --perlin code
      task.wait()
    end
  end
end

instead, use a god damn hashmap! (fancy word for dictionary)

sorry if i seem harsh but i have experience in doing computationally expensive stuff like that in roblox

used to, now when i used heartbeat its still slow, so i use my method.

yea but dude you will get better performance not using your method at all at that point

What’s the benefits of using this over something simple like the below?

local function MiliWait(Time)
    return task.wait(Time / 1000)
end

thanks for testing, like i said, i didn’t know if it DID actually work for actual milliseconds, as i only used it for making my loops slightly accurate instead of lower ms values.

i will actually update this because i had an oversight to the code whereas i would STILL wait for a frame even if the values passed onto the mswait function was under the duration of the frame.

this should fix some issues about the timings and should work as intended.
@binky007 helped me a bit figuring out atleast what the problem was, and this should hopefully work, i’ve not tested this new version because i can’t at the moment.

local function MiliWait(Time)
    local NOW = os.clock()
    local Time = Time * 0.001
	local dt

    if Time >= 0.020 then
        repeat
            dt = task.wait()
        until os.clock() + dt >= NOW + Time
    end

    repeat
        while true do break end
    until NOW + Time <= os.clock()
end
3 Likes