#How do I make it so this script runs every 10 seconds without using task.wait()?

1 messages · Page 1 of 1 (latest)

eager gale
median spear
thin wind
#

you can use dt

eager gale
median spear
eager gale
#

hell no

eager gale
median spear
thin wind
#

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

eager gale
#

i see

#

no i dont

thin wind
#

and dont relay on ai its not good long term

eager gale
#

ima kinda new and i dunno what that is

median spear
hushed carbonBOT
#

studio** You are now Level 1! **studio

eager gale
#

or how to use it

median spear
#

ai is good

thin wind
#

just search up brawl dev for renderstepped

thin wind
eager gale
thin wind
#

ive used it an its not good for advanced stuf

median spear
median spear
thin wind
thin wind
#

start using it bro

median spear
thin wind
#

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

eager gale
#

cuz i alr am using that

eager gale
median spear
eager gale
#

so

#

im not gonna use task.wait

median spear
eager gale
#

but if delta time keeps track of the time between frames, how would I tell the script if ten seconds has passed?

thorny moon
eager gale
#

so i should use os.clock() to keep track if 10 seconds has passed

#

why didnt i think of that...

thorny moon
#

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

eager gale
#

the entire function to run every ten seconds

#

i was out of ideas so im making the computer minigame from flee the facility

eager gale
#

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

thorny moon
#

i do feel like there are a lot of potential repeated event bindings in your code though, through both the InputBegan & Heartbeat events

eager gale
#

repeated event bindings?

thorny moon
#

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

eager gale
#

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

thorny moon
thorny moon
eager gale
#

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

thorny moon
# eager gale i think

thats right, a task.wait loop would halt your function
to fix that, you can always use a coroutine, or task.delay

eager gale
#

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

thorny moon
#

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
eager gale
#

so task.spawn() does this?

hushed carbonBOT
#

studio** You are now Level 5! **studio

eager gale
#

ive never even heard of that function before lol

#

the more i know ig

#

but wouldnt that create more connect function?

thorny moon
eager gale
#

wait nvm

oak wing
# eager gale so task.spawn() does this?
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

thorny moon
eager gale
thorny moon
#

and also, to "disconnect" a task-created coroutine just use task.cancel

eager gale
#

so i can disconnect after i walk away

#

thank you so much!

thorny moon
#

np, hope your game goes well 🙂‍↕️

eager gale
#

i shouldve tested this

#

What do I put in the cancel perimeters?

thorny moon
hushed carbonBOT
#

studio** You are now Level 19! **studio

eager gale
#

ok thank you again lol

icy plinth
#

if currenttime - starttime > 10 then

winged oyster
icy plinth
eager gale
#

Da hell

#

I got my name from the meaning of the word

#

I’ve never touched the word

winged oyster
topaz epoch
#

use RunService.Heartbeat its better imo

still urchin
#

Like why not use task.wait honestly

static jacinth