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.
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.
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)
Thank you so much it works!
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
This isn’t answering the question.... don’t read as fast next time
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!
tick() just keeps going up.
well yea, you would have to use some math.
(its tick() - StartTime) remember to do StartTime = tick() at the end of the function (after print())
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Use :tick()