Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to kick if a player says an innapropiate word?

Asked by 4 years ago

i want to kick a player if they say something bad in my game but it only works if they only say the bad word can i get help?

current code

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg == "stupid" or msg == "trash" or msg == "clapped" or msg == "claped" or msg == "stoopid" then
            plr:Kick("Bad words")
        end
    end)
end)

2 answers

Log in to vote
0
Answered by 4 years ago

I see that the other answer suggested using an array, but the issue with this is that it would take far too long to include all "hashtagged" words that the ROBLOX Chat System detects.

Fear not, for ROBLOX has a service that has filter functionality. You will need to have the LocalPlayer defined first.

You'd use:

local textService = game:GetService("TextService");
local text = textService:TextFilterContext(message, player.UserId, 1); -- replace message with your message, and player.UserId with the UserId of the player. This will filter the text based on the player's settings. The 1 is context. 1 = PublicChat, 2 = PrivateChat.

Learn more about TextService here: https://developer.roblox.com/en-us/api-reference/class/TextService

After filtering, check if the string is hashtagged and kick the player.

0
Yh but what he ment was well lets say he made a fps game he wouldnt want people flexing on others kind of thing because they wont be # EnzoTDZ_YT 275 — 4y
Ad
Log in to vote
4
Answered by 4 years ago

i see what you mean you want to have it check if the player says the message i explained more below

local list = {"stupid", "trash", "clapped", "claped", "stoopid"} --Contains inappropriate words.
function checkString(message)
    for i,v in pairs(list) do --Go through the list
        if v:lower() == message:lower() then --Check if the message is the same as a word in the list
            return true
        end
    end
end

game.Players.PlayerAdded:connect(function(Player) --When a player joins
    Player.Chatted:connect(function(Message) --When the player chats
        if checkString(Message) then --If what they chatted was inappropriate
            Player:Kick("\n\nYou Said An Innapropiate Word In Our Game!\n\n") --Kick them from the game.
        end
    end)
end)
0
thanks :D worked LoganDaBoss14 17 — 4y
0
your welcome EnzoTDZ_YT 275 — 4y
1
Accept his answer haba_nero 386 — 4y

Answer this question