How to check if more than 4 players spam something in chat?

How do I make a script that can check if more than 4 players spam something in chat? lets say the word “O” if they spam it in chat how would i make it so a sound plays for everyone? (basically the server)

How can I do this? please help! and provide an example script

2 Likes

We cannot provide you a full working script to let you achieve your goal, you should use your ideas and knowledge to script.

But what we can give you, are ideas on how you can achieve your goal.

First, what is the spam threshold? What do you consider “spam” in your case? Is it spam when 4 players are typing the same exact message more than 4 times in the chat? You can use Player.Chatted event which fires when a player chats in game. You should implement a logic which checks if another player has said the same exact message, and that another player has said the message just right after a few milliseconds the first player has chatted, then add them in a table. Continue to do so until there are 4 players in that table, and then play an Audio which should be parented to workspace. Any audio parented under workspace can be heard by all players.

spam like if they spam o 10 times, and thank you i will try doing this.

You need to be clear of what you consider a spam. There is no way I can help you scripting this whole system. You have to think by yourself, I have already given you an idea which you can implement.

wdym by clear im saying if the 4 players spam O 10 times then the sound plays for everyone

As stated before by @ItzMeZeus_IGotHacked , you can use Player.Chatted in this case.

For your wants, you could firslty make a variable for the amount of times something must be chatted for it to be considered spam, like:

local NeededForSpam = 10

then, a variable to count how many times the word has been chatted,

local SpammedTimes = 0

with these you can then use Player.Chatted to increment the value of SpammedTimes, then check if it has reached the desired limit. If so, do whatever.

ex:

local NeededForSpam = 10
local SpammedTimes = 0
local SpamWord = “O”

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if msg == SpamWord then
SpammedTimes +=1
end
if SpammedTimes == NeededForSpam then
print(“omg they spammed”)
end
end)
end)

The only problem with this script is that, they can just wait for around 10-20 seconds to say the same message again, which can’t be considered as a spam. A spam typically means the same message being said multiple times in a specific time interval (2 exact messages said in 0.5 seconds).

Now there is a variable that tracks the last time it was said compared to the current time, change the line that states:

"if currentTime - LastMessageTime < 5 the "

with any number (seconds) that you want.

local NeededForSpam = 10
local SpammedTimes = 0
local SpamWord = "O"
local LastMessageTime = 0

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local currentTime = os.time()
		if currentTime - LastMessageTime < 5 then
			SpammedTimes = SpammedTimes + 1
		else
			SpammedTimes = 0
		end
		LastMessageTime = currentTime
		if msg == SpamWord then
			if SpammedTimes == NeededForSpam then
				print("omg they spammed")
			end
		end
	end)
end)
3 Likes

Ty man for the help, in the end i did have to modify the script but this script helped me understand! ty

of course, best of luck with your game!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.