Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Filtering Chat Problem May I Have Some Help?

Asked by
Prestory 1395 Moderation Voter
6 years ago

So i have a chat that im trying to filter but i keep getting the error

21:03:08.956 - Argument 2 missing or nil

This is my code for filtering it.

script.RemoteEvent.OnServerEvent:Connect(function(player,msg)
player.Chatted:Connect(function(msg)
local first = string.sub(msg, 1,3)
if first == "/me" then
if game.Players.LocalPlayer.Character.Head:FindFirstChild("Emote") then
game.Players.LocalPlayer.Character.Head.Emote:Destroy()
end
local gui = Instance.new("BillboardGui", game.Players.LocalPlayer.Character.Head)
local str = game:GetService('Chat'):FilterStringForBroadcast(player)
gui.Name = "Emote"
gui.Size = UDim2.new(7,0,1.5,0)
gui.StudsOffset = Vector3.new(0,3.5,0)
local label = Instance.new("TextLabel", gui)
label.Text = str "**"..script.Parent.Parent.Name.." says "..string.sub(msg, 5,string.len(msg)) ..""

Thanks for your help.

1 answer

Log in to vote
0
Answered by 6 years ago

The [FilterStringForBroadcast](http://wiki.roblox.com/index.php?title=API:Class/Chat/FilterStringForBroadcast) command takes two arguments: stringToFilter and PlayerForm. You would have to provide the string so it can properly apply Roblox's filter.

Here's a version of your code using it correctly:

script.RemoteEvent.OnServerEvent:Connect(function(player,msg)
player.Chatted:Connect(function(msg)
local first = string.sub(msg, 1,3)
if first == "/me" then
if game.Players.LocalPlayer.Character.Head:FindFirstChild("Emote") then
game.Players.LocalPlayer.Character.Head.Emote:Destroy()
end
local gui = Instance.new("BillboardGui", game.Players.LocalPlayer.Character.Head)
gui.Name = "Emote"
gui.Size = UDim2.new(7,0,1.5,0)
gui.StudsOffset = Vector3.new(0,3.5,0)
local label = Instance.new("TextLabel", gui)
label.Text = game:GetService("Chat"):FilterStringForBroadcast("**"..script.Parent.Parent.Name.." says "..string.sub(msg, 5,string.len(msg)) .."", player)
Ad

Answer this question