Still have questions? Join our Discord server and get real time help.
10

# ?Understandable Lua Tutorial - Tick() function [MEDIUM]? [closed]

XDvvvDX 186
6 months ago

Hello! Today I will teach about the Roblox tick() function.

1) So, what is tick()? Tick is a function that shows the amount of secounds that have passed since January 1st 1970, yes, it's pretty weird and it sounds useless but keep reading and we'll explain more.

2) So how can tick() be used? Tick has a few specific uses, but probably the one that you'll use the most is to calculate the time between one point in your game to another. Like in trails, etc.

3) So how do you use tick()? So. To use tick, we'll set a variable first and just define tick() as a variable.

local t = tick()


Now. We'll use the most common use, calculate the time since the game started until a brick is touched. Basically, the tick starts to count since the game has started, since the script is also. So, whenever the game starts the count is starting.

local t = tick()

function onTouch(hit)
print(tick()-t)
end

script.Parent.Touched:Connect(onTouch)


Basically, when the countdown starts we create a new tick in the print line, and minus the old tick which is basically an amount of time since the game has started. So, when you touch the brick it returns the time that has passed since the game has started. So, that's it. I hope it was helpful!

0
This man deserves a like TheRealPotatoChips 793 — 6mo
0
also, check the URL at the top of the screen, it's almost at 100000! TheRealPotatoChips 793 — 6mo
0
Though this is insightful, this unfortunately isn’t the best place to post this. There is a game on the front-page called “Lua Learning”. It has a global tutorial library, that you can post a tutorial to with all the same features StackEdit provides, all the while you can mark a difficulty too! Ziffixture 5707 — 5mo

### Closed as off-topic by Ziffixture

This question has been closed by our community as being off-topic from ROBLOX Lua Scripting.