How To Make A Caps Detection System (With Warnings & UI)

Hello, this is a simple and effective tutorial for a caps abuse detection system

  1. Insert a server script into ServerScriptService. You can name it anything.
    caps

The first line of code we will write will be declaring a variable for the “Players” service.

local playerservice = game:GetService("Players")
  1. Then the second will be declaring the max number of warnings a player can recieve & the players kick message
local maxWarnings = 2
local kickMessage = "Player Kicked For Using Full Caps In A Setence."
  1. Declare a function
local function capsDetect(text) -- make sure to include a paramater for text or else this won't work

end
  1. This will be the code inside of the function
local function capsDetect(text)
    local gsub = string.gsub(text, " ", "")  -- this removes all spaces from a text, making it easier to filter/look through with string patterns

	if string.match(gsub, "^%u+$") then -- if the string can be matched to a string pattern (Entire Sentence Capital) then
		return true -- the string pattern was found, returns the function true
	else
		return false -- the string pattern was not found, returns the function false
	end
end
  1. Now that the main part/function is done, we can move onto the second to last part
playerservice.PlayerAdded:Connect(function(player) -- fires when the player is added
	local data = Instance.new("Folder", player) -- creates a new folder inside the player
	data.Name = "Data"
	local warning = Instance.new("IntValue", data) -- creates a Int value inside the folder for warnings
	warning.Name = "Warnings"

	repeat wait() until workspace:FindFirstChild(player.Name) -- yields the script until it can find the players character in workspace
  1. Making a Overhead UI for Warnings
    There are 2 ways of doing this, Instancing & Cloning
-- Instancing Within The Script
	local billboardUI = Instance.new("BillboardGui") -- Creates a billboardGui to display over the players head
	billboardUI.Enabled = false -- [ Properties
	billboardUI.Name = player.Name
	billboardUI.AlwaysOnTop = true
	billboardUI.Size = UDim2.new(3, 0, 1, 0)
	billboardUI.StudsOffset = Vector3.new(-1, 2, 0) -- Properties ]

    local text = Instance.new("TextLabel", billboardUI) -- Makes a textlabel inside the billboradUI
	text.TextScaled = true -- [ Properties
	text.BackgroundTransparency = 1
	text.RichText = true
	text.TextColor = BrickColor.new("Really red")
	text.Size = UDim2.new(1.5, 0, 1.5, 0)
	billboardUI.Parent = player.Character
	billboardUI.Adornee = player.Character:FindFirstChild("Head") -- Properties ]

OR

-- Cloning from ReplicatedStorage
	local UIClone = game:GetService("ReplicatedStorage"):WaitForChild("BillboardGui"):Clone() -- Clones a BillboardGUI object inside of replicated storage (If there is one)
	UIClone.Parent = player.Character:FindFirstChild("Head") -- Parents it to the players head

  1. Now finally, the last part, the player message
	player.Chatted:Connect(function(message) -- runs the code below when a player chats
			if warning.Value < maxWarnings then -- if the players warnings is less than the maxWarnings then
				warning.Value += 1 -- Add 1 warning

				billboardUI.Enabled = true -- Enables billboardUI inside of the player
				text.Text = "Warnings: "..warning.Value -- Sets the textlabel to number of player warnings
			elseif warning.Value == maxWarnings then -- If the players warnings are equal to the max warnings then
				player:Kick(warning.Value.. " Warnings: "..kickMessage) -- kick the player from the game
			end
		end
	end)
end)

The Final Code should look something like:

local playerservice = game:GetService("Players")
local maxWarnings = 2
local kickMessage = "Player Kicked For Using Full Caps In A Setence."

local function capsDetect(text)
	local gsub = string.gsub(text, " ", "")
	
	if string.match(gsub, "^%u+$") then
		return true 
	else
		return false
	end
end

playerservice.PlayerAdded:Connect(function(player)
	local data = Instance.new("Folder", player)
	data.Name = "Data"
	local warning = Instance.new("IntValue", data)
	warning.Name = "Warnings"
	
	repeat wait() until workspace:FindFirstChild(player.Name)
 	
	local billboardUI = Instance.new("BillboardGui")
	billboardUI.Enabled = false
	billboardUI.Name = player.Name
	billboardUI.AlwaysOnTop = true
	billboardUI.Size = UDim2.new(3, 0, 1, 0)
	billboardUI.StudsOffset = Vector3.new(-1, 2, 0)
	
	local text = Instance.new("TextLabel", billboardUI)
	text.TextScaled = true
	text.BackgroundTransparency = 1
	text.RichText = true
	text.TextColor = BrickColor.new("Really red")
	text.Size = UDim2.new(1.5, 0, 1.5, 0)
	billboardUI.Parent = player.Character
	billboardUI.Adornee = player.Character:FindFirstChild("Head")
	
	player.Chatted:Connect(function(message)
		if capsDetect(message) then
			if warning.Value < maxWarnings then
				warning.Value += 1
				billboardUI.Enabled = true
				text.Text = "Warnings: "..warning.Value
				
				print("Warning: "..warning.Value)
			elseif warning.Value == maxWarnings then
				player:Kick(warning.Value.. " Warnings: "..kickMessage)
			end
		end
	end)
end)

Official string patterns reference: String Patterns

9 Likes

I personally wouldn’t use this as it issues a “warning” every time without any leniency. You should have incorporated a strike system to make this better as the docs for string patterns basically explain what you did here.

1 Like

A strike system or some sort of punishment like a warning would be good to go with this as well, other than that nice job!

1 Like

Alright thank you! This is my first devforum post, I was kind of nervous.

1 Like

I redid the script and added a strike system. Thank you for the feedback

2 Likes

Man, this will help these cafe games so much.

3 Likes

Whats problem of CAPS ? Why do you kick him

4 Likes

I have a few criticisms of this script.

  • You do not give the player a visible warning for having their message filled with uppercase characters. Since the player cannot see the messages since the print() is server sided and most players don’t know how to use the Developer Console. Therefore, the player does not know what they were kicked for due to the message being “2 Warnings”. A possible fix for this is having a GUI warning when the user gets a warning with a explanation or a more descriptive kick with information about why the player was kicked. For example: “You used full-caps in a sentence more than 2 times.”

  • I would recommend changing the uppercase detection to at least 3 or more letters at the beginning of a sentence. Most people type fast and can sometimes accidently uppercase more letters at the beginning (for example 1 letter extra capital letter is the most common that I’ve seen). Users would be way more worried about how they would type the beginning of the sentence if they don’t want to be kicked, and probably mad about it too. I would also recommend checking the last few letters in a sentence where it is extremely unlikely for it to be capitalized.

  • Other languages mostly don’t have capital letters so it wouldn’t be possible to localize this if you’re planning to give your game support for other languages (which probably won’t be the case since most of the games that have these kind of rules are English only)

5 Likes

Thank you for the feedback, I will keep it in mind!

I was a little bit confused while reading the 2nd bullet point, the detection system currently checks the entire sentence for capitals, and if the entire sentence is, then it will give a warning.

2 Likes

cool. But what if someone has their caps lock button broken or bypass it with simply putting 1 letter lowercase?

2 Likes

I am working on fixing that.

This text will be blurred

2 Likes

There is a better system than just detecting if all characters are uppercase, capture the number of the uppercase letters, count the whole string using string.len , then divide the count of whole string by 2 and if the numbers of uppercase letters is higher or the same as the divided whole string number, warn them

2 Likes

Not to be rude, but what’s the problem with caps? Every role play game has a seizure any time u put caps. All your doing is killing ur fanbase before it even starts

3 Likes

This is just a tutorial man, I’m just teaching people how to make a system like this.

2 Likes

Yo can some explain to me why people hate caps so much, like how is it spam

2 Likes

I belive in the minds of some creators behind roleplay games it is “immature” and “unproper”

I don’t really know

3 Likes