How do I do a message activated script execute after clicked?

Hello, Im trying to do a message activated script. I am using a local script in startercharacterscripts to do this, What I want to happen is when u type a message then click on your screen a function happens. At the moment I’ve only got a print that happens once saying the message and clicking for testing.

local UIS = game:GetService("UserInputService")
local Players = game.Players
local Player = Players.LocalPlayer
local Character = Player.Character

task.spawn(function()
    Player.Chatted:Connect(function(Spell)
        Spell = string.lower(Spell)
        if Spell == string.lower("Test") then
            UIS.InputBegan:Connect(function(MouseClick)
                if MouseClick.UserInputType == Enum.UserInputType.MouseButton1 then
                    print("here")
                end
            end)
        end
    end)
end)

I was just wondering if I did something wrong or if there’s a fix for this? because the script does not work at all, I know to add a connect then disconnect the uis once clicked however I haven’t added that yet till I’m sure the script works.

Player.Chatted does not work for local scripts. An alternative is TextChatService.SendingMessage:

local TCS = game:GetService("TextChatService")

TCS.SendingMessage:Connect(function(ChatMessage)
	local ChatText = ChatMessage.Text -- this is the (filtered) text that the player has said
	
	-- rest of code goes here
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.