Why string.sub(5)
though, what part of it are you trying to remove?
Why do you need the player’s name anyways? You can just use UserId to find the player by looping through all the players until you find the player with the correct UserId. You should probably save who gets admin permissions by UserId anyways.
I know, but if you want to make a system that’s sending the info about using the command into a discord server’s channel via webhook?
Ok, at least get rid of the UserId and ConvertedName though. You can just use PlayerName.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But it will send the username we wrote after the “/js” command, not the exact one. For example, if I type “/js roblox”, it will send username: roblox instead of username: Roblox or smth like that.
Huh, I didn’t even know that you could get the UserId from a lowered UserName. I guess it’s fine then.
Lol, but it works very well. It’s returning me the Roblox username after using /js roblox (it’s converted the username into the actual one).
But, if we found the solution for the chat command script, how to hide the command from the chat after using it?
local Players = game:GetService("Players")
local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"
command.Triggered:Connect(function(player)
local playerId = player.UserId
for _, player in ipairs(Players:GetPlayers()) do
if player.UserId == playerId then
print(player.Name.." fired this command")
end
end
end)
Here is an example of how it could work using the “command.Triggered” thing.
I’m not sure how to delete messages with the new TextChatService.
Ok, but what’s the sense of using for … do?
Alr, I’ll test the script out rn
As far as I know, to find the matching player (since there is much more you can do with the player than just the player’s name) you need to loop through all players in the server.
… Annndddd never mind you can just use Players:GetPlayerByUserId(); updated code:
local Players = game:GetService("Players")
local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"
command.Triggered:Connect(function(player)
local playerId = player.UserId
local player = Players:GetPlayerByUserId(playerId)
print(player.Name.." fired this command")
end)
Why I need to loop it?
Nah, that characters system is the worst.
I updated the post, you can just use Players:GetPlayerByUserId()
Ok I just realized what you were talking about, the whole thing i did was so dumb lol
local Players = game:GetService("Players")
local chat = game:GetService("TextChatService")
local command = Instance.new("TextChatCommand")
command.Parent = chat:WaitForChild("TextChatCommands")
command.PrimaryAlias = "/tp"
command.Triggered:Connect(function(player)
print(player.Name.." fired this command")
end)
But I know this lol, I wrote the same function in the script above