How do I make an Auto Grammar script?

I want to make a script that automatically edits a users message with grammar corrections. How would I do this?

You can easily place dots at the end of the message, correcting words will be a bit harder and it will probably require you to use external servers.

I have seen other games use it. For instance Vinns Hotels uses it.

What exactly does it correct?

This text will be blurred

It will replace abbreviated words (e.g. thx) with the full word. It will also add full stops at the end.

use string.split(message, ' ') in order to get a table with every word, process every word replacing abbreviated words with full form. use string.sub(message, #message, #message) to check if theres a dot in the end, if u haven’t found it, simply add it.

3 Likes

Just check when the textbox updates, then if it includes abbreviated text, which you can check with an if statement, replace it to the full word.

Autocorrections can incorrectly correct messages, resulting in unintended messages. Are you sure you are needing this and not intrusively hinder messages? Is there more reasons you’d do it? A better question is: How much of the grammatical error do you intend to correct?

1 Like

The easiest method I can think of is to create a table of common errors and their fixes. Then do a for loop on the player’s input to see if what they have typed matches anything in your table. If something is found, you replace what they have typed with the correct version.

https://create.roblox.com/docs/reference/engine/classes/Chat

Sample script you would use in ServerScriptService

local Players = game:GetService("Players")

local grammarMistakes = {
	[1] = {
		["Mistake"] = "peice",
		["Fix"] = "piece"
	},
	[2] = {
		["Mistake"] = "alot",
		["Fix"] = "a lot"
	}	
}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		player.Chatted:Connect(function(message)
			
			for i = 1, #grammarMistakes do
				local checkForMistake = string.match(message, grammarMistakes[i].Mistake)
				if checkForMistake then
					print("mistake detected")
					local newMessage = message:gsub(checkForMistake, grammarMistakes[i].Fix)
					message = newMessage

				end
			end	
			-- TODO add message to the chatbox
			print(message)
		end)
	end)
end)


autoCorrect.rbxl (35.0 KB)