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)
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])
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)
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)
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
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
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)