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.

1function chat()
2 
3end
4game.Players.LocalPlayer.Chatted:Connect(chat)

Now we need to be able to get the message:

1function chat(msg) -- while we're using "msg", you can use anything.
2 
3end
4game.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.

1function chat(msg)
2word = 'apple'
3if string.match(msg,word) ~-nil then game.Players.LocalPlayer:Kick('You said '..word)
4end
5game.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
5 years ago

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

In ServerScriptService:

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

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