So I'm trying to make a lag detector but apparently this happens. I don't know why.
local one = print(elapsedTime())
wait()
local two = print(elapsedTime())
local final = two - one
print(final)
What the heck?
So I'm trying to make a lag detector but apparently this happens. I don't know why.
local one = print(elapsedTime())
wait()
local two = print(elapsedTime())
local final = two - one
print(final)
What the heck?
This doesn't work because the function, print, returns a string. You cannot subtract 2 strings, you can only subtract values.
So, for this you would do
local one = elapsedTime()
wait()
local two = elapsedTime()
local final = two - one
print(final)
This will return a Number Value.
If you want a whole number, you would use:
math.floor (Rounds Up)
math.ceil (Rounds Down)
local one = elapsedTime()
wait()
local two = elapsedTime()
local final = math.floor(two - one)
print(final)
local one = elapsedTime()
wait()
local two = elapsedTime()
local final = math.ceil(two - one)
print(final)
Hope this helped! If this worked, let me know by selecting this as the answer!
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
My guess is the print part on one and two. Try doing it without the print?
Yeah, I just tested it, and it worked without the print.
Because print returns a string, and you can't subtract one string from another, they have to be values.
You can also use tick(), works just about the same. Returns the same number.
If you want a whole number, use math.floor(two-one)
thanks