Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Are their anyways of making a timer going on while a script is going on?

Asked by
SuperFryX 130
7 years ago

Basically, is there any kinda code that is similar to game:GetService("Debris"):AddItem where it does a countdown but lets the script keep going?

0
The simplest way to do this is use the spawn() http://wiki.roblox.com/index.php?title=Threading User#5423 17 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

There are a couple.

I don't know why you would want to use any of these other methods, but I'll go over them anyways.

  • First Method,

The first idea is using the Delay Function. Here's the link to the wiki page about the delay function. An example would look like this,

script.Parent.Touched:connect(function(part)
    delay(1,function()
        part:Destroy()
    end)
end)

Here's a short gif of this script in action.

  • Second Method,

Another is to use the Spawn Function. This works similarly to the first method, but you can't pass the amount of time you want to wait into the function. This can easily be done with a wait, but it's worth noting.

script.Parent.Touched:connect(function(part)
    spawn(function()
        wait(1)
        part:Destroy()
    end)
end)

I hope that gives you some insight, and that this answer was what you wanted.

Good Luck!

If I helped, please don't forget to accept my answer!
0
I would still recommend the debris service, but delay would be my second choice. User#11440 120 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

I have not used this function personally, but from what I've read on the wiki, delay is what you are looking for. Use it like this:

delay(time, func)

Where time is the time in seconds and func is the function to run.

Answer this question