Hello, this is a simple and effective tutorial for a caps abuse detection system
- Insert a server script into ServerScriptService. You can name it anything.
The first line of code we will write will be declaring a variable for the “Players” service.
local playerservice = game:GetService("Players")
- 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."
- Declare a function
local function capsDetect(text) -- make sure to include a paramater for text or else this won't work
end
- 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
- 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
- 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
- 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