Input Timing Accuracy

Welcome back Dev Forum, I am back to ask a question that I don’t think anyone has had to ask yet. But I am curious on which is more accurate between timing.

  1. Using a click detector.
  2. Using UI’s and TextButtons.
  3. Using UserInputService and then detecting whether the player has hit the object or missed.
    The timings here are crucial as it would affect the score the player receives.
2 Likes

Interesting questions. I’ll go benchmark and I’ll be back.

2 Likes

Thank you, I do not currently have time to produce these tests myself, and I also think that this information may be useful for some people. Please may you include how you did these benchmarks so that I can also replicate them, whilst also letting other people view how this was solved. :slight_smile:

1 Like

No problem! Alright, after testing it seems that to detect clicking UserInputService is the winner.

I actually don’t know how/if you can benchmark clicks. So what I did is I added a print in each script for each method and saw which printed first. I clicked multiple times (and even ran an autoclicker for a little) and every time the print for UIS printed first. Code:

(UIS, Local Script StarterPlayerScripts)

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

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local Target = mouse.Target
		print("Clicked U", Target)
	end
end)

(Script inside Click Detector)

local Target = script.Parent.Parent
script.Parent.MouseClick:Connect(function()
	print("Clicked C", Target)
end)

(Local Script In Text Button)

local mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.MouseButton1Click:Connect(function()
	local Target = mouse.Target
	print("Clicked B", Target)
end)
1 Like

How did you run each one simultaneously? Due to not being able to click all 3 at the same time.

1 Like

The UserInputService can run along side both at once. So I first checked if the UIS is faster than clicking the part, then check to see if it’s faster than clicking the text label. I don’t think theres anyway to compare the speeds of the text button VS the Click Detector (because their meant for dif things)

3 Likes

I have just ran the benchmarks myself with your code, however I decided to some tick differences and here was my result.

The code I added:

local mouse = game.Players.LocalPlayer:GetMouse()
local tick1 = tick()
script.Parent.MouseButton1Click:Connect(function()
	print(tonumber(tick())-tonumber(tick1))
	local Target = mouse.Target
	print("Clicked B", Target)
end)

image

1 Like

The tick is inaccurate here as it starts as soon as you join and not when you click the part…

1 Like

That is true, I will rewrite this to make it more accurate. Oops, what an oversight!

1 Like

But either way, as you saw the UIS printed first.

1 Like

I have decided that I will use UserInputService. Thank you for this.

2 Likes