Help every time I run this it just print random numbers:
function starttimer()
local timetostart = tick()
local function checktime()
local nowtime = tick()
print(tick() - timetostart)
end
checktime()
end
starttimer()
Help every time I run this it just print random numbers:
function starttimer()
local timetostart = tick()
local function checktime()
local nowtime = tick()
print(tick() - timetostart)
end
checktime()
end
starttimer()
The reason you’re getting random numbers printed every time you run the code is because you’re calling the tick()
function multiple times without storing the initial value. Each time you call tick()
, it returns the current time in seconds since the game started. So, in your code, you’re calculating the difference between the current time and the current time repeatedly, which gives you varying results.
To fix this, you need to store the initial time when you start the timer and then calculate the difference between the current time and the stored initial time. Here’s an updated version of your code:
function starttimer()
local timetostart = tick()
local function checktime()
local nowtime = tick()
print(nowtime - timetostart)
end
checktime()
end
starttimer()
In this updated code, timetostart
is set to the initial time using tick()
when starttimer()
is called. Then, inside the checktime()
function, the current time is obtained again using tick()
and the difference between nowtime
and timetostart
is printed, giving you the elapsed time since the timer started.
Now, when you run the code, it should print the correct elapsed time instead of random numbers.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.