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

How much time approximately does it take for part of a script to be executed?

Asked by 3 years ago

Let's say I want to make part of a game music-based, where something happens in the rhythm of the BGM. And let's say the tempo is 120 and the code in the script is:

01while true do
02 
03wait(4)
04 
05script.Parent.Transparency = 1
06 
07script.Parent.CanCollide = false
08 
09wait(4)
10 
11script.Parent.Transparency = 0
12 
13script.Parent.CanCollide = true
14 
15end

Now, if this is tested, you can see that it doesn't exactly match the tempo after a few. So the only thing I need to know is how long it takes for something like "script.Parent.Transparency = 1" to be executed in the script so I can adjust the wait times.

1 answer

Log in to vote
2
Answered by
Neatwyy 123
3 years ago
Edited 3 years ago

Keep in mind that wait(x) is not accurate and will sometimes yield a few milliseconds longer than desired, also know that wait(x) is deprecated and task.wait(x) should be used instead. If you really want to know how long it takes to run a code like that though, you can see how much time has elapsed using the tick() or os.time() function.

1local Elapsed = os.time()
2 
3script.Parent.Transparency = 1
4 
5script.Parent.CanCollide = false
6 
7print(os.time() - Elapsed)
0
"This will work." BadPiggie411 47 — 3y
Ad

Answer this question