Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to kick if a player says an innapropiate word?

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

✓ Accepted answer

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.

1 comment

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 #

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)

3 comments

0

thanks :D worked

0

your welcome

1

Accept his answer

This discussion is preserved as it was. New answers, comments, and votes are closed.