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

Is there a possible way to cancel the chat when you type something spesific?

Asked by 5 years ago
Edited 5 years ago

Hello! I was just wondering if thrre is a way to cancel the output of what you type in the chat.

For example if you type in "help", it will cancel it, players wouldnt be able to see the message but it will do something.. like play a sound of a tutorial. I already have a script.

voicehelp = script.Sound

game.Players.PlayerAdded:connect(function(plr)
            plr.Chatted:connect(function(message)
                      If message == "help"
                      voicehelp:Play()

My question is what should I add to the script to prevent the "help" message going into the chat.

I did code in a different game, there I could use "cancel event" so the message wont be executed but I could do different stuff after you type in the message.

0
Edited. Using /e hides the chat. User#19524 175 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You have a few capitalisation errors, especially on the if and end). You are also missing a then, as well as an end to finish your if chunk. Let me fix your code.

local voiceHelp = script.Sound -- use local variables

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg, recipient)
        if msg == "/e help" and not recipient then -- if they are not whispering
            voiceHelp:Play()
        end -- you were missing an end
    end)
end)

On a side note, switch to Connect, as ROBLOX may remove connect in the future.

0
Oh I know I got errors in the script. Lol. Thanks anyway. I am just on my mobile so I didnt really spent so much time writting the whole script but I have a working script. Already tested it. So is there a way to cancel the chat? HeyItzDanniee 252 — 5y
0
What do you mean by cancel chat? User#19524 175 — 5y
0
I think he means that when you type "help" it doesn't appear in the chat window. Zenith_Lord 93 — 5y
0
Yeah. HeyItzDanniee 252 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Hi Dannie,

Yes, you could do that by checking the Internal chat system that Roblox has implemented, and going to the place that holds the messages and deleting any messages that have the Text that you want to delete. So, the code would look something along the lines of:

Local Script Inside StarterGui

local message_holder = script.Parent:WaitForChild("Chat"):WaitForChild("Frame"):WaitForChild("ChatChannelParentFrame"):WaitForChild("Frame_MessageLogDisplay"):WaitForChild("Scroller"); -- The Frame that holds the messages

local texts = { -- The texts that you want to dissapear.
    "help";
    "blah";
    "remove me";
    "i hate myself";
}

function remove_message(child)   -- The function, child is the Instance that is added to the message holder.
    local frame = child; 
    local txt_label = frame:WaitForChild("TextLabel"); -- The TextLabel that has each players' message inside.
    local text = txt_label.Text:lower();     -- The message that was added, in lowercase.

    for _, txt in next, texts do  -- Loop through all of the texts to see if any of them match what's inside the message that was added.
        if text:match(txt) then -- If they match, then
            frame:Destroy(); -- It gets destroyed
        end
    end
end

message_holder.ChildAdded:Connect(remove_message); -- Connecting the .ChildAdded function to the Event. 

Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

Answer this question