Roblox text chat command not triggering *i added images*

so, i made a text chat command in TextChatService and when i type the command, it doesnt work.

–more explanation

hirearchy of the textchatcommand

image

the script

script.Parent.Triggered:Connect(function(ots)
	local plr = game.Players[ots.Name]
	game.ReplicatedStorage.WarnPlayer:FireClient(plr,"just work")
	print("sadsad")
end)

the output after running the command

  12:01:51.984  game name* @ date* auto-recovery file was created  -  Studio
  12:01:52.371  Animation Spoofer cannot run while game is running  -  Server
  12:01:52.682  Animation Spoofer cannot run while game is running  -  Client

the command is /test

game link if you want to test it out yourself

The way you’ve written your code is that the player has to enter a username exactly for it to be found inside game.Players. Most likely you aren’t spelling your name exactly as it is.

In your usage case, you’d most definitely want to be using the unfilteredText (second parameter of Triggered) to get the username. I would recommend looking up how to get a player from username partial instead of you being required to type out the full username.

okay, ill try that way instead!

sorry,but it shouldve printed “sadsad” when it is triggered by anyone at all, no other parameters are needed.it just doesnt trigger at all

It won’t print because it’d error when it tries to find a player that doesn’t exist. Check your output if theres any errors.

Output widget can be enabled under the View tab.
image

1 Like

i already have output open though

want me to send an video of me typing the command?

sorry but i couldnt upload the video

Did some testing and I believe I found the problem!
The issue here is that scripts don’t run inside TextChatService like how LocalScripts don’t run inside the Workspace. In your case, you need to have your script inside ServerScriptService and then find the command inside TextChatService and connect to Triggered there.

-- ServerScriptService/script.lua

local TextChatService = game:GetService("TextChatService")

local MyCommand = TextChatService:WaitForChild("TextChatCommand")

MyCommand.Triggered:Connect(function(textSource, message)
    print("Hello world!")
end)

Also, if you haven’t already, you need a slash in your command alias for it to appear as one in the chat box.
image

1 Like

Thanks, Your solution worked just fine!

1 Like

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