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

[Custom Chat] How to add FilterStringAsync?

Asked by 6 years ago
Edited by M39a9am3R 6 years ago

Okay, so im trying to use a Custom Chat i found.. (Ofcourse im going to edit it..) But first im trying to make it works with FilterStringAsync.. But when i try it it gives errors and stuff ;-; tried to look up a custom chat with FilterStringAsync but couldnt really find one :/

Please help me with this

local chats = script.Parent.Chats
local last

function newChat(msg,plr)
    if #msg > 0 then
        for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end

        if plr.Name == "" then
        newMessage.TextColor3 = script.Owner.Value
        newMessage.Text = "[OWNER] " .. plr.Name ..": ".. msg

        elseif plr.Name == "" or plr.Name == "" or plr.Name == "" then
        newMessage.TextColor3 = script.Admin.Value
        newMessage.Text = "[ADMIN] " .. plr.Name ..": ".. msg

        elseif game:GetService("GamePassService"):PlayerHasPass(plr, 0)then
        newMessage.TextColor3 = script.VIP.Value
        newMessage.Text = "[VIP]" .. plr.Name ..": ".. msg

        else 
        newMessage.Text = plr.Name ..": ".. msg
        end

        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
    end
end

function join(plr)
    for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end 
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " joined the server!"
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
end

function left(plr)
    for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end 
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " left the server."
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
end

game.Players.PlayerAdded:connect(function(plr)
    join(plr)
end)

game.Players.PlayerRemoving:connect(function(plr)
    left(plr)
end)

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        newChat(msg, plr)
    end)
end)

for i, player in pairs(game.Players:GetPlayers()) do
    player.Chatted:connect(function(msg)
        newChat(msg, player)
    end)
end
0
The message is being created via the function 'newChat', so it would be best to filter the string there using FilterStringBroadcast, here is a pretty neat tutorial: https://www.youtube.com/watch?v=Ph1nCEIlZ2c YabaDabaD0O 505 — 6y
0
the problem is that if i try to add :FilterStringForBroadcast or :FilterStringAsync to the function it says "Unknown Global: 'newChat'" CrazyScript3r 67 — 6y
0
I heard FilterStringAsync is deprecated, I agree with YabaDabaD0O User#22219 20 — 6y
0
Watch the language! Profanity is not allowed on the website. https://scriptinghelpers.org/help/community-guidelines M39a9am3R 3210 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try adding this the newChat function, but as a side note, FilterStringForBroadcast only works on Servers

local chatservice = game:GetService("Chat")
local newmessage = chatservice:FilterStringForBroadcast(msg, plr)

Then change msg to newmessage OR You can wait until the message is filtered, since the custom chat your using is using the Chatted event. So you could add:

wait(.1)

Or any other number you want.

0
If your filtering it manually, then you need pcall: http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#pcall User#22219 20 — 6y
Ad

Answer this question