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

Why does my kick on chat script doesn't work? Making a family friendly game.

Hi there, back with another kick script needing help.

So this time I need help with this, why does my "kick on chat" script doesn't work?

local canKick = {"LocalPlayer"}

game.Players.PlayerAdded:Connect(function(plr)
	for _, c in pairs(canKick) do
		if plr.Name == c then
			plr.Chatted:Connect(function(msg)
				if string.sub(msg,1,5) == "Damn" then
					local pl = game.Players:FindFirstChild(string.sub(msg,7))
					if pl then
						pl:Kick("Kicked for bad language.")
					end
				end
			end)
		end
	end
end)

Just wanting help with this, just making a family friendly chat game! ;)

Thanks!

4 comments

0

is this a server script

0

What if they write the swear word somewhere else in their message? Also, why do you not use Roblox's default chat filter?

0

Why? People can counter it dude. Seen people saying words such as Phak etc. That BYPASSES Roblox's horrible tagged chat filter anyways. LOL.

0

If an API made by professionals is bypassed then I don't see how you can do any better https://developer.roblox.com/articles/Text-and-Chat-Filtering

1 answer

You would want to use other string methods so they can't bypass the filter so easily. The find and lower keywords would work good for this case.

local Kickable = {"ThatPreston"}

game.Players.PlayerAdded:Connect(function(Player)
	for _, Entry in pairs(Kickable) do
		if Entry == Player.Name then
			Player.Chatted:Connect(function(Message)
				Message = string.lower(Message) -- > make the message lowercase
				if string.find(Message, "damn") then -- > check if damn is in the message
					Player:Kick("Kicked for bad language.") -- > kick the player
				end
			end)
		break
		end
	end	
end)

You'd want to put this script in ServerScriptService, ideally. You didn't clarify where or what your previous script was, but you'd typically want something like this on the server, in a normal script. I hope this helps! Good luck!

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