How Do I moderate this warning system

So I found a good warning system however you can put curse words as the warning, how do I fix this?

Code:

local GroupId = 1234567
local MinimumRankToUseCommand = 9

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local WarningGUI = script.WarningGUI:Clone()
		WarningGUI.Parent = Character.Head
	end)
	
	Player.Chatted:Connect(function(Message)
		local SplitMessage = Message:split(" ")
		if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
			local NameOfPlayerToWarn = SplitMessage[2]
			local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
			local Reason = Message:split(NameOfPlayerToWarn)[2]
			
			local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
			local CurrentWarnings = WarningGUI.Warnings
			
			CurrentWarnings.Value = CurrentWarnings.Value + 1
			WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason
			
			if CurrentWarnings.Value >= 3 then
				PlayerToWarn:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
			end
		end
	end)
end)
2 Likes
local TextService = game:GetService("TextService")

game.ReplicatedStorage.FilterText.OnServerInvoke = (function(player,Reason)
	local filteredTextResult = TextService:FilterStringAsync(Reason, player.UserId)
	return filteredTextResult:GetNonChatStringForBroadcastAsync()
end)

you will need a filter function in order to do that(roblox only filters chat strings)
i suggest checking Text Filtering | Documentation - Roblox Creator Hub
here is the filter function i use:

function f(message)
	local TextService = game:GetService("TextService")
	local RunService = game:GetService("RunService")
	if RunService:IsStudio() then return message end
	local Success, Error = pcall(function()
		message = TextService:FilterStringAsync(message, game.CreatorId)
	end)
	if Success then
		local FilterSuccess, FilterError = pcall(function()
			message = message:GetNonChatStringForBroadcastAsync()
		end)
		if FilterSuccess then
			return message
		end
	end
	local result = ""
	for i = 1, string.len(message) do
		result = result .. "#"
	end
	return result
end

this will replace the whole message with #### in case the filtering fails

to make this work you need to put this function above game.Players.PlayerAdded event and replace
local Reason with local Reason = f(Message:split(NameOfPlayerToWarn)[2])

1 Like

still doesn’t work. There are no errors.

Code:

local GroupId = 6741421
local MinimumRankToUseCommand = 9

function f(message)
	local TextService = game:GetService("TextService")
	local RunService = game:GetService("RunService")
	if RunService:IsStudio() then return message end
	local Success, Error = pcall(function()
		message = TextService:FilterStringAsync(message, game.CreatorId)
	end)
	if Success then
		local FilterSuccess, FilterError = pcall(function()
			message = message:GetNonChatStringForBroadcastAsync()
		end)
		if FilterSuccess then
			return message
		end
	end
	local result = ""
	for i = 1, string.len(message) do
		result = result .. "#"
	end
	return result
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local WarningGUI = script.WarningGUI:Clone()
		WarningGUI.Parent = Character.Head
	end)
	
	Player.Chatted:Connect(function(Message)
		local SplitMessage = Message:split(" ")
		if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
			local NameOfPlayerToWarn = SplitMessage[2]
			local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
			local Reason = f(Message:split(NameOfPlayerToWarn)[2])
			
			local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
			local CurrentWarnings = WarningGUI.Warnings
			
			CurrentWarnings.Value = CurrentWarnings.Value + 1
			WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason
			
			if CurrentWarnings.Value >= 3 then
				PlayerToWarn:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
			end
		end
	end)
end)

Like I said above, I suggest just invoking the server though a local script and have an event which is fired in order to do this:

CurrentWarnings.Value = CurrentWarnings.Value + 1
WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason

Your script would be parented to the WarningGUI and would look like this

local Event = game.ReplicatedStorage:WaitForChild("Warning") -- add an event called "Warning" in ReplicatedStorage
local filterFunction = game.ReplicatedStorage:WaitForChild("FilterWarn") -- add a function called "FilterWarn" in ReplicatedStorage

Event.OnClientEvent:Connect(function(Reason,PlayerToWarn)
   local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
   local CurrentWarnings = WarningGUI.Warnings
   local filteredText = filterFunction:InvokeServer(Reason) -- will filter the warn reason

   CurrentWarnings.Value = CurrentWarnings.Value + 1
   WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason

   if CurrentWarnings.Value >= 3 then
      PlayerToWarn:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
end)

Then on the server you would want to receive the Invoke and fire the event

local TextService = game:GetService("TextService") -- TextService variable

Player.Chatted:Connect(function(Message)
   local SplitMessage = Message:split(" ")
   if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
   local NameOfPlayerToWarn = SplitMessage[2]
   local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
   local Reason = f(Message:split(NameOfPlayerToWarn)[2])
			
   local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
   local CurrentWarnings = WarningGUI.Warnings

   local playerName = PlayerToWarn.Name

   game.ReplicatedStorage.FilterWarn.OnServerInvoke = (function(playerName,Reason) -- server receives invoke
      local filteredTextResult = TextService:FilterStringAsync(Reason, player.UserId) -- filters string
      return filteredTextResult:GetNonChatStringForBroadcastAsync() -- returns filtered string to the client
   end)

   game.ReplicatedStorage.Warning:FireClient(Reason,PlayerToWarn)
1 Like

Thanks, Roblox gave me an error for this line:

			game.ReplicatedStorage.FilterWarn.OnServerInvoke = (function(playerName, Reason) -- server receives invoke

(line 24)

and the error is

15:17:08.334 - OnServerInvoke is not a valid member of RemoteEvent “ReplicatedStorage.FilterWarn”

15:17:08.341 - Stack Begin

15:17:08.345 - Script ‘Workspace.WarnCommand’, Line 24

15:17:08.347 - Stack End

It needs to be a RemoteFunction not an event

1 Like

OOOH. Both of them or just the FilterWarn?

Nevermind I got that to work, but then I got this error

game.ReplicatedStorage.Warning:FireClient(Reason, PlayerToWarn)

(line 29)

16:52:02.565 - Unable to cast value to Object

16:52:02.568 - Stack Begin

16:52:02.571 - Script ‘Workspace.WarnCommand’, Line 29

16:52:02.572 - Stack End

Sorry for the late reply, I fixed a few things in my script that I realized to be mistakes

local groupId = 0000
local minRank = 0

Player.Chatted:Connect(function(Message)
	local SplitMessage = Message:split(" ")
	if SplitMessage[1] == "!warn" and Player:GetRankInGroup(groupId) >= minRank then
		local NameOfPlayerToWarn = SplitMessage[2]
		local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
		local Reason = Message:split(NameOfPlayerToWarn)[2]

		local WarningGUI = workspace[PlayerToWarn.Name].Head.WarningGUI			
        local CurrentWarnings = WarningGUI.Warnings
		local playerName = PlayerToWarn.Name

		game.ReplicatedStorage.FilterWarn.OnServerInvoke = (function(playerName,Reason) -- server receives invoke
			local filteredTextResult = TextService:FilterStringAsync(Reason, Player.UserId) -- filters string
			return filteredTextResult:GetNonChatStringForBroadcastAsync() -- returns filtered string to the client
		end)
			
		CurrentWarnings.Value = CurrentWarnings.Value + 1
		WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason

		if CurrentWarnings.Value >= 3 then
			PlayerToWarn:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
		end

		game.ReplicatedStorage.Warning:FireClient(PlayerToWarn,Reason)
	end
end)
local Event = game.ReplicatedStorage:WaitForChild("Warning") -- add an event called "Warning" in ReplicatedStorage
local filterFunction = game.ReplicatedStorage:WaitForChild("FilterWarn") -- add a function called "FilterWarn" in ReplicatedStorage

Event.OnClientEvent:Connect(function(Reason,PlayerToWarn)
	local filteredText = filterFunction:InvokeServer(Reason) -- will filter the warn reason
end)

Should work now! My bad, (Reason,PlayerToWarn) should have been switched so the player comes first

Great! Everything works except the

event.

It gives me this error:
Workspace.WarnCommand:6: attempt to index nil with ‘Chatted’

Well because I only showed the Chatted event part of the script, you have to add it to PlayerAdded event.

local TextService = game:GetService("TextService")
local groupId = 0000
local minRank = 0

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local WarningGUI = script.WarningGUI:Clone()
		WarningGUI.Parent = Character.Head
	end)
	
	Player.Chatted:Connect(function(Message)
        -- The rest of your code

Argument 1 missing or nil

on the local script line 5

local Event = game.ReplicatedStorage:WaitForChild("Warning") -- add an event called "Warning" in ReplicatedStorage
local filterFunction = game.ReplicatedStorage:WaitForChild("FilterWarn") -- add a function called "FilterWarn" in ReplicatedStorage

Event.OnClientEvent:Connect(function(PlayerToWarn,Reason)
	local filteredText = filterFunction:InvokeServer(Reason) -- will filter the warn reason
end)