Scripting Question

How do I fix the filter function on this script, everything but it works. Basically the script sensors everything instead of just curse words. I said YAY and it was censored by the warning system.

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)
2 Likes

Do you specifically know what’s not working ?

To effectively get help with fixing your code, try to more closely isolate what is not working by bugfixing, then explain your thought process behind the code and what you’ve tried to fix it.

1 Like

sorry @wevetments and @Tyler148 I added more detail now!