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

How do I kick somebody from the server if they say a word?

Asked by 6 years ago

I am making a Code Blockers script so when the player says the code out loud 'Was I Hard?' they are kicked from the server. I don't want to ban them, I want them to play again! Please help Code Hunters 2 is opening in 2 days!

local Blockers = {"Was I Hard?}

game:GetService("Players").PlayerAdded:connect(function(newPlayer)
    newPlayer.Chatted:connect(function(newMessage)
        for index, value in pairs(Blockers) do
            game.Players.LocalPlayer:Kick("Sorry, you have been kicked from the server. Please do NOT spoil the codes or ruin the other robloxians experience. You are not banned so you could rejoin.")
        end
    end)

4 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

If statement

Neither of the answers posted thus far solve anything. You want your program to do something if a player says a certain word or phrase anywhere in a message. Keyword, if. You were off to a good start, creating a list containing the words or phrases you want to blacklist. However, there's no comparison to these blacklisted words or phrases with anything the player actually wrote. This is where you want an if statement to handle this comparison, then do something after.

Revision

A quick revision will include some updated functions and methods of old common practices. The condition of our if statement will depend upon the match function checking to see if the filtered word or phrase was found anywhere in the message string.

local Players = game:GetService("Players")

local blacklist = {
    "phrase #1", "phrase #2", "phrase #3";
    "word #1", "word #2", "word #3";
}

-- Creating an event listener for individual players when differentiation isn't important, is now obsolete and can be replaced with the PlayerChatted event (member of Players service).

-- Also get in the habit of using "Connect" opposed to "connect", as the latter is deprecated.
Players.PlayerChatted:Connect(function(messageType, player, message)
    for _, filtered in next, blacklist do
        if string.match(message, filtered) then
            player:Kick("Reason")
        end
    end
end)

If you have any questions, just leave a comment and I'll get back to it as soon as possible.

Ad
Log in to vote
0
Answered by 6 years ago

This will work; but they will have to say exactly "Was I Hard?" with the question mark and everything.

local Blockers = {"Was I Hard?"}

game:GetService("Players").PlayerAdded:connect(function(newPlayer)
    newPlayer.Chatted:connect(function(newMessage)
        for index, value in pairs(Blockers) do
            if newMessage == value then
                game.Players.LocalPlayer:Kick("Sorry, you have been kicked from the server. Please do NOT spoil the codes or ruin the other robloxians experience. You are not banned so you could rejoin.")
            end
        end
    end)
end)
Log in to vote
-3
Answered by 6 years ago

im not a god or anything but maybe its because you used "LocalPlayer" instead of an argument maybe?

Log in to vote
-3
Answered by 6 years ago
local Blockers = {"Was I Hard?"}

game:GetService("Players").PlayerAdded:connect(function(newPlayer)
    newPlayer.Chatted:connect(function(newMessage)
        for index, value in pairs(Blockers) do
            game.Players.LocalPlayer:Kick("Sorry, you have been kicked from the server. Please do NOT spoil the codes or ruin the other robloxians experience. You are not banned so you could rejoin.")
        end
    end)

i cant test this cause my enter key broke, but tell me if this does work

Answer this question