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

How to kick a player when they say a certain word in a sentence?

Asked by 7 years ago

I already have the script I made for kicking the player when they say a certain word only. I was wondering if there was a way to make it so if someone says it in a sentence, It also kicks them. Any help would be appreciated, Thanks!

2 answers

Log in to vote
0
Answered by 7 years ago

You'll have to use the .Chatted event. http://wiki.roblox.com/index.php?title=API:Class/Player/Chatted

In a localscript create your everyday function.

function chat()

end
game.Players.LocalPlayer.Chatted:Connect(chat)

Now we need to be able to get the message:

function chat(msg) -- while we're using "msg", you can use anything.

end
game.Players.LocalPlayer.Chatted:Connect(chat)

With this newfound data we will use string manipulation to find the word, we have two options: string.match() and string.find() The first one returns the word if its found, the second returns where the word is in the string. We're going to use string.match.

function chat(msg) 
word = 'apple'
if string.match(msg,word) ~-nil then game.Players.LocalPlayer:Kick('You said '..word)
end
game.Players.LocalPlayer.Chatted:Connect(chat)

Wow that was easy, right? Sometimes the answer can be resolved with a little research, try that next time.

0
You said the magic word FixRobloxz 61 — 5y
0
wiw Vortex_Vasne 89 — 5y
Ad
Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago

Someone already beat me to this, but this script is slightly better.

In ServerScriptService:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        msg = string.lower(msg) -- If player uses weird caps, it will still work.
        if msg == "apple" then
            plr:Kick("You said the word")
        end
    end)
end)

The other person's script didn't have a line this one had. This makes so the player can say "aPPLE" and it wouldn't count. But because of this line, you could say "APPLE" and the line converts the letters to lowercase.

Answer this question