so, i made a text chat command in TextChatService and when i type the command, it doesnt work.
–more explanation
hirearchy of the textchatcommand
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 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.
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.