Incorrect WPM calculation

Hello,

I’m trying to make a script to detect wpm, but the calculations seem off.

   ▼  {
    [1] = "I",
    [2] = "am",
    [3] = "typing",
    [4] = "su"
  }  -  Client - LocalScript:12
  WPM: 235.80462354951877  -  Client - LocalScript:48

I’m not sure what causes it, as the calculation is simple:

TextBox.Focused:Connect(function()
	LastTime = tick()
end)

local function CalculateWPM()
	local words = string.split(TextBox.Text, " ")

	print(words)
	
	return #words * 60 / (tick() - LastTime)
	
end

TextBox.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		local wpm = CalculateWPM()
		print("WPM:", wpm)
	end
end)

Thank you.

Off how? We don’t know how fast you typed, so there’s no way to know if the number is correct.

They are counting as when the player started focusing on the text box as when they started typing.

The fastest I type is 130wpm, there’s no way I reached 235.

Also is the formula not just words/timeInMins

So in your case:

return #words / ((tick() - LastTime)/60)

Are you sure it’s wrong? The calculation doesn’t seem wrong - you first calculate the words per second and convert it to words per minute. Can you try typing longer sentences and words and then checking if it is more correct? Because you’ve got to remember that you typed 3 very short words (I, am, su) so it’s not unlikely to get that low of a score. Tell us if it looks more correct or if it’s still off.

Seems to have made it worse.

   ▼  {
    [1] = "I",
    [2] = "am",
    [3] = "typing",
    [4] = "a",
    [5] = "sentech",
    [6] = "which",
    [7] = "is",
    [8] = "longer,",
    [9] = "which",
    [10] = "gives",
    [11] = "me",
    [12] = "plenty",
    [13] = "of",
    [14] = "time",
    [15] = "to",
    [16] = "mess",
    [17] = "up",
    [18] = "and",
    [19] = "go",
    [20] = "back",
    [21] = "and",
    [22] = "correct",
    [23] = "myself,",
    [24] = "which",
    [25] = "should",
    [26] = "slow",
    [27] = "it",
    [28] = "down."
  }  -  Client - LocalScript:12
  WPM: 1652.2951382440501  -  Client - LocalScript:48

And here’s the same with a longer sentence:

   ▼  {
    [1] = "I",
    [2] = "am",
    [3] = "typing",
    [4] = "a",
    [5] = "longer",
    [6] = "sentence",
    [7] = "again,",
    [8] = "which",
    [9] = "should",
    [10] = "make",
    [11] = "it",
    [12] = "accurate.",
    [13] = "I",
    [14] = "am",
    [15] = "not",
    [16] = "typing",
    [17] = "that",
    [18] = "fast."
  }  -  Client - LocalScript:12
  WPM: 535.7816955941303  -  Client - LocalScript:21
   ▼  {

Save this to a variable called timeInMins and print it out.

There seems to be something wrong with the (tick() - LastTime) part. It seems to always be equal to around 1.

Take a look at this:
In your last example, you typed 18 words and got a result of 535.7816955941303. Dividing this by 60 and 18 (your number of words), then taking the inverse, you get ~2.016s. (sorry jesus I think I copied the wrong values here) That doesn’t seem to be right. I don’t think you only typed for two seconds.

Not sure what could be wrong here, but .Focused seems to be firing more often than once.

1 Like

Seems to be working correctly now.

   ▼  {
    [1] = "I",
    [2] = "am",
    [3] = "typing",
    [4] = "at",
    [5] = "60+",
    [6] = "probably."
  }  -  Client - LocalScript:12
  0.06529621283213298  -  Client - LocalScript:13
  WPM: 91.88689111714285  -  Client - LocalScript:22
1 Like

For what it’s worth, “WPM” is usually not literally the number of words in a minute.

Quoting https://web.archive.org/web/20150923174328/http://www.asarif.com/pub/papers/arif_ticsth09.pdf:

Transcribed Text (T) is the final text entered by the
participant, and |T| is the length of T.

WPM = (|T|-1) / S * 60 * 1 / 5

Here, S is time in seconds measured from the first key press
to the last, including backspaces and other edit and modifier
keys. The constant 60 is the number of seconds per minute, and
the factor of one fifth accounts for the average length of a word
in characters including spaces, numbers, and other printable
characters [3]. Note that S is measured from the entry of the
very first character to the last, which means that the entry of the
first character is never timed, which is the motivation for the “–
1” in the numerator of (1). While this assures accuracy, other
researchers sometimes omit this factor.

In other words, if you’re making a WPM typing test-like input box, this paper suggests using local words = (#TextBox.Text - 1) / 5

It also suggests starting your timer when the first character is pressed after focusing, rather than immediately when focusing.

That paper has more good info about how typing errors can be used to adjust the final score.

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.