How to make a chat command like "/tp" that nobody else instead of me can't see?

Hi. I’m trying to make a script that can teleport to player on other server by writing “/js username”. I have a system in my game that saves player server’s JobId or PrivateServerId (if server identified as Public one, it will save the JobId and will set the PrivateServerId datastore to “”), but I need a chat command that can teleport me on the server that the player on (like Blox Fruits has) without my own message in the chat. Help!

1 Like

And yeah, it would be great to find an easy example on making these scripts (for chat commands).

I searched on internet, but there’s a lot of scripts that I can’t understand.

It’s not the easiest way. It has modules and etc, but I need to make it into a single script.

local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"

command.Triggered:Connect(function()
	print("code")
end)

But lol, it’s not identifying the player after /tp, it’s just executing the same code every time.

But it’s not explaining how to use this in the script.

local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"

command.Triggered:Connect(function(_, m)
	local playername = m:sub(5)
print(playername)
end)

Then, what’s _ and m means? Is “m” the player’s name?

And why it says (5) instead of (2) or smth like that?

Returns the substring of s that starts at i and continues until and including j. i and j can be negative. i defaults to 1 and j defaults to -1.

1 Like

Now I don’t understand anything lol.

I think I’ll try out to remake this script: Imgur: The magic of the Internet

This is exactly what I used to make my command script but I didn’t realize that there was a “TextChatCommands” thing. I probably wouldn’t use the script you sent.

Also, @MrOnlyKemal what’s up with the string.sub(5) because can’t you just print the entire name or, better yet the display name.

By the way, what they were trying to say was that you can use:

local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"

command.Triggered:Connect(function(player)
	local playerName = player.Name
	print(playerName)
end)

image
Why? This script is the easiest one you can find out on the devforum.

The problem is that if you use “/js GamesVitaliy” it will return gamesvitaliy instead of GamesVitaliy, but you can just solve this via converting the username into id and then converting it back.
It won’t matter if you use “/js GamesVitaliy” or “/js GaMeSvItAlIY” (for example) and return the normal username as the result.

It does? Can you send your output when trying this script?

I mean only if you convert the username thing after “/js” to UserId via Players service and then convert it back to the username.

It prints the Player who ran the command, my code is a LocalScript that’s meant to fire a RemoveEvent with the target name