#How do I make it so this script runs every 10 seconds without using task.wait()?
1 messages · Page 1 of 1 (latest)
use ai
you can use dt
brchacho
ai can find a way trust
dt?
fine as a software engineer ill help you
delta time its the variable apssing in through renderstepped
its the amount of time passed between the last frame
you can use that instead of task.wait
and dont relay on ai its not good long term
ima kinda new and i dunno what that is
did yu try using task.delay
** You are now Level 1! **
or how to use it
just search up brawl dev for renderstepped
no its not bro....
doesnt that still halt the entire function?
ive used it an its not good for advanced stuf
yu right
use RunService.Heartbeat
erm actually it halts the thrread if u didnt use ai you would know that!
i didnt use ai lmao
start using it bro
holy glaze
hhahaha
yea all jokes aside use ai to help you learn its goated for that but once u get good enough to code without it just leave it for ssyntax and just simple recommendations
i will do this
why are you using talk.wait if yu dont even want a delay
i dont want it to delay
so
im not gonna use task.wait
alr
so I use runservice.renderstepped and keep track of delta time?
but if delta time keeps track of the time between frames, how would I tell the script if ten seconds has passed?
instead of delta time, i would just have a loop that continuously checks if the current os.clock() is greater than the recorded "cooldown until" os.clock() + 10
so i should use os.clock() to keep track if 10 seconds has passed
why didnt i think of that...
though, im not sure what your aversion is to task.wait
also, are you wanting the quickTimeEvent to run every tren seconds? or the game.RunService.Heartbeat's function to run
the entire function to run every ten seconds
i was out of ideas so im making the computer minigame from flee the facility
that sounds fun
i shouldve added that as context...
but yeah in flee there is a qte that appears in a fixed time
so thats what im tryna do
i do feel like there are a lot of potential repeated event bindings in your code though, through both the InputBegan & Heartbeat events
repeated event bindings?
if you run the quickTimeEvent twice, it could create two inputBegan listeners. so if you were to press E, it would run the function inside uis.InputBegan:Connect(function(input) ... end) twice
it really depends if the player is guaranteed to disconnect the inputConnect before the next quicktime event though
i just dont know if it is guaranteed from the logic in your code <-- but i could be wrong, since i havent read into it a ton
yes i made sure to disconnect the connect function
both of them as well
either when i get too far from the computer or if i complete the minigame
i still needa write it for when i fail
oh alright, thats good then 🙂↕️
ya that might help 😬
so basically
i have a function that calls this function
so i dont want to use task.wait since it will halt my other function
i think
thats right, a task.wait loop would halt your function
to fix that, you can always use a coroutine, or task.delay
i see
its just that after i call this function, i want it to run every 10 seconds on its own without halting my other function.
would os.clock() work?
or do i use coroutine or task.delay
so, from what i understand you have a function "A" that you want to call this function "quickTimeEvent". e.g.,
local function A()
...
-- run this every ten seconds
quickTimeEvent()
-- allow the next lines to play immediately after
...
end
``` if you want it to work every ten seconds, ```lua
local function A()
...
task.spawn(function()
while task.wait(10) do
quickTimeEvent()
end
end)
--this will run immediately, it will not wait the 10 seconds
...
end
so task.spawn() does this?
** You are now Level 5! **
ive never even heard of that function before lol
the more i know ig
but wouldnt that create more connect function?
ya, task.spawn() creates a coroutine that lets multiple processes run at once
wait nvm
i see
local runner
local timer = 0
runner = rs.Heartbeat:Connect(function(dt)
timer += dt --stack dt
if timer < 10 then return end
timer = timer - 10
--functions
end)
alternative if you want it to disconnect
Edit: change from
timer = 0
to timer = timer - 10
this would work, but to avoid accumulating arithmetic errors dont stack dt, just use os.clock()
ohh so thats how u keep track of dt
ah
and also, to "disconnect" a task-created coroutine just use task.cancel
ok i was bouta ask that
so i can disconnect after i walk away
thank you so much!
np, hope your game goes well 🙂↕️
sorry to notify you again
i shouldve tested this
What do I put in the cancel perimeters?
task.spawn returns a coroutine, so put that coroutine into task.cancel(). e.g., ```lua
local c = task.spawn(function()
...
end)
...
task.cancel(c)
** You are now Level 19! **
ok thank you again lol
if currenttime - starttime > 10 then
are you the guy from valorant
what's ur rank diddyblud

use RunService.Heartbeat its better imo
Like why not use task.wait honestly
true