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

How to figure out the time between each click?

Asked by 4 years ago

So I want to make a script that finds out the time in between clicks.

For example:

Player clicks

Player clicks again

Prints the time before he clicked the second time

I really need help! So thank you in advance.

0
Use :tick() MmadProgrammer 35 — 4y

3 answers

Log in to vote
1
Answered by
herrtt 387 Moderation Voter
4 years ago

Ok here you go, this should print the time difference between each click (currenttime - lasttime = difference).

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

local lasttime = tick()
mouse.Button1Down:Connect(function()
    local t0 = tick()
    local timediff = t0 - lasttime -- pro maths here

    print("Last click was " .. timediff .. " seconds ago!")

    lasttime = t0 -- The other answers didn't update the last time :(
end)

(an upvote would be appreciated)

0
Thank you so much it works! ScriptedEli 101 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Add a Debounce.

Local db = false

If not db then
db = true
--Do something
wait (1) -- How long the duration of the click again
db = true
0
This isn’t answering the question.... don’t read as fast next time MmadProgrammer 35 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Pretend this Script is a child of a ClickDetector, and you're changing a part color.

local StartTime = tick()
local ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function()
    workspace.Part.BrickColor = BrickColor.new("Fog") -- example Part
    print("This took: "..StartTime - tick()) -- you can use math.abs() to get the absolute value i think, not sure dont judge me :(
end)

Please accept this answer if this helped!

0
tick() just keeps going up. ScriptedEli 101 — 4y
0
well yea, you would have to use some math. Tyler090130 619 — 4y
0
(its tick() - StartTime) remember to do StartTime = tick() at the end of the function (after print()) herrtt 387 — 4y

Answer this question