Would this work efficiently?

before I start showing this note that I know there are many options for waiting, I just want to know if this works well at all as I’ve never tried it.

function Sleep(Count)
    if Count == nil then
        Count = 0
    elseif type(Count) ~= “number” then
        return warn(“this would be a warn message”)
    end
    local OSTime = os.time()
    while true do
        if os.time() - OSTime >= Count then
            break
        end
    end
end

while true do Sleep()
    print(“at school on my phone rn, extremely bored”)
end

any thoughts on this?
how well would this work and can it be improved?

1 Like

added checks to the code to make sure it’s better

1 Like
while true do Sleep()
print("at school on my phone rn, extremely bored")
end

This would probably crash your game since you aren’t stalling the function from executing indefinately.

it wouldn’t stall it at all???

1 Like

I got this reply from my last post, I’m guessing mine wouldn’t work because I’m not using coroutines to yield properly

1 Like

You can just basically replace that with custom wait if its your “wait method”

you do know my initial question was if this would work or not

I never said I was going to use it and it isn’t even that original so it’s not really mine

1 Like

You’ve asked for feedback I gave you the feedback - avoid using unnecessary while true loops and as somebody said it will crash your game because there isn’t wait() anyways.

oh I thought you meant to replace my code with the custom wait link, sorry :sweat_smile:

2 Likes