How to make a notification appear when a player says something

Hello, so im trying to make a system in which when a player says "/tweet message " then everyone can see a notification that says the message the player said, i tried finding it on youtube and devforum but there seems to be no topics like this.

2 Likes

Very simply, use the player.Chatted event. Then, check if the player said “/tweet” and retrieve everything after the first space " ". After that, fire an event to all clients, triggering a notification on the client side. Remember to secure your code using rate limits; otherwise, exploiters could spam notifications. Additionally, use the Roblox filter to filter messages and ensure your code is safe.

2 Likes

i tried that buy the only problem on my way is that i have no idea how to check if the player said “/tweet somethingrandom” i tried “/tweet” … msg … and “/tweet” … msg but none worked.

1 Like
local tweetCommand= "/tweet"
local function onPlayerChatted(player, message)
	if message:sub(1, tweetCommand:len()):lower() == tweetCommand then

	end
end

Just take a look at the roblox documentations it shows very well explained examples

i got a qucik question, am i suppost to paste the thing that will happen in the “tweet command then” segment?

I don’t understand your question.

1 Like

(my english is bad, sorry) so im basically asking, when you got the “tweetCommandthen” part in the script, am i suppost to replace “tweetCommandthen” with the code that will run after saying “/tweet stuff” ???

1 Like

No, it’s not finished. You won’t get far if I simply send you a piece of code to copy and paste. That’s why I want you to figure it out on your own. I’ve provided the necessary documentation.

okay, thank you

20 + 10 character limit or sum like dat.

Okay i figured it out, ima paste it in here so people can see this:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Str)
		if (string.sub(Str, 1, 7) == "!tweet ") then 
			local Msg = string.sub(Str, 8, string.len(Str))
			print(Msg)
		end
	end)
end)
2 Likes

Thanks for sharing! Just a very little suggestion, people may use “!tweetanything” and it would output “nything” as the Msg. Maybe use "!tweet " (with a space) as the command instead (and change 1, 6 to 1, 7).

thanks for the little suggestion, ill use that!

2 Likes