Greetings, fellow developers.
I need help with creating my message command. I’m currently trying to create a command that shows text when it’s used. When someone says it in the chat box, it shows a ScreenGui and shows the message of the user that used the command. Like this:
:topmessage Welcome to my game!
“Welcome to my game!” would be visible on a GUI for everyone in the server.
The problem I am currently having with this is filtering inappropriate words. I’ve looked at the Developer Hub but I’m not advanced at scripting, so I’m currently out of options.
Here’s my current server script so far:
local Settings = {
["GroupId"] = "4789069";
["AllowedRank"] = 13
}
local replicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local event = replicatedStorage.FilterText
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local messageArgs = msg:split(" ")
if messageArgs[1]:lower() == ":topmessage" and plr:GetRankInGroup(Settings.GroupId) >= Settings.AllowedRank then
local commandReason = msg:sub(messageArgs[1]:len() + 2,-1)
local player = plr.Name
game.ReplicatedStorage.SendTopMessage:FireAllClients(commandReason, player)
print(plr.Name .. " has shouted: " .. commandReason) -- Debug
elseif msg == ":clrtop" and plr:GetRankInGroup(Settings.GroupId) >= Settings.AllowedRank then
local player = plr.Name
game.ReplicatedStorage.RemoveMessage:FireAllClients(player)
end
end)
end)
game.ReplicatedStorage.FilterText.OnServerInvoke = (function(player, commandReason)
local filteredTextResult = TextService:FilterStringAsync(commandReason, player.UserId)
return filteredTextResult:GetNonChatStringForBroadcastAsync()
end)
Here’s my local script inside the GUI:
game.ReplicatedStorage.SendTopMessage.OnClientEvent:Connect(function(commandReason,player)
script.Parent.Enabled = true
local filteredText = game.ReplicatedStorage.FilterText:InvokeServer(commandReason)
script.Parent.Message.Text.Text = commandReason
script.Parent.TitleBar.Title.Text = "Pinned Message from "..player
end)
game.ReplicatedStorage.RemoveMessage.OnClientEvent:Connect(function(player)
print(player.." has cleared the shout")
script.Parent.Enabled = false
end)
If you think I need to add, remove, or change anything to the scripts above, please let me know.
Thank you all for your help!