Hi! I am trying to make a block of code that calculates the amount of time a player’s left mouse button is being held down. The variable is called timeDrag, and resets whenever a player is pressing the left mouse button (this sets dragging to true). Since I want milliseconds and so on, I cannot update it every second. The current code I am using doesn’t work at all, there is a huge margin of error between the real life time and the timeDrag time.
Tick() gets you a very accurate time measurement., and you’ll need 2 of them to get what you’re looking for. Typically it’d be like this:
--Let's assume Mouse is already set.
local TickSave = 0
Mouse.Button1Down:Connect(function()
TickSave = tick()
end)
Mouse.Button1Up:Connect(funciton()
local Time = tick()-TickSave
if Time>=10 then --Or what ever time you're looking for.
--Your code here.
end
end)
This is a very good measure of time but I believe the OP wants it down to the millisecond of precision and I believe tick() only is down to the exact second.
Opening the command bar in studio and putting in print(tick()) will give that output.
Though given the method that tick() uses to get the time, this is why you need 2 of them and subtract from the most recent tick().
Aaah I see! I tried changing my wait up to 0.05 seconds, it works perfectly!
I’ve never used tick() in my scripts before but I guess I could give it a try