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
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.
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.
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)