I know this may not be useful to some people but it is to me. It can be used for in-game moderators to join and find exploiters, players can join friends in a different server, etc…
The command takes a specific username, when running the command you should check double check the name you entered.
Here is a video of it working:
1. Chat Commands
Chat commands a pretty basic, so I won’t be explaining it. This is a normal script inside of ServerScriptService
.
local Commands = {}
local Prefix = "/"
local Admins = { -- You can use any way to check for admins, this is just a UserId Checker
"631458856" --WestJordan08 | DodoSeal
}
for _, v in ipairs(script:GetChildren()) do
if v:IsA("ModuleScript") and v:FindFirstChild("Cmd") then
Commands[v.Cmd.Value] = require(v)
end
end
game.Players.PlayerAdded:Connect(function(Plr)
Plr.Chatted:Connect(function(Msg)
for i, v in pairs(Admins) do
if v == tostring(Plr.UserId) then
local SplitString = string.split(Msg, " ")
local SlashCommand = SplitString[1]
local Command = string.split(SlashCommand, Prefix)
local CmdName = Command[2]
if Commands[CmdName] then
local Arguments = {}
for i=2, #SplitString, 1 do
table.insert(Arguments, SplitString[i])
end
Commands[CmdName](Plr, Arguments)
end
end
end
end)
end)
Now you want to make a ModuleScript
as a child of the main script. You can name it whatever you want, just make sure you have a string value named Cmd
with a value of what you want the command to be (ex. if the value is kill
, the command would be /kill
).
Now you want to return a function with the parameters Sender, Arguments
. Arguments is a table of everything the player said excluding the command. Sender is the player instance that executed the command.
Inside the command module, paste this script:
local MsgService = game:GetService("MessagingService")
return function(Sender, Arguments)
local TargetUser = Arguments[1]
if TargetUser then
MsgService:PublishAsync("JoinUser", {TargetUser, Sender.Name})
end
end
2. Finding the target user
To find the target user in the game servers, make a script inside ServerScriptService
and paste this inside:
local MsgService = game:GetService("MessagingService")
MsgService:SubscribeAsync("JoinUser", function(Message)
if game.Players[Message.Data[1]] then
MsgService:PublishAsync("FoundUser", {game.JobId, Message.Data[2]})
end
end)
Then make a script as a child of that and paste this inside:
local MsgService = game:GetService("MessagingService")
local TeleportService = game:GetService("TeleportService")
MsgService:SubscribeAsync("FoundUser", function(Message)
if Message.Data[1] ~= game.JobId and game.Players[Message.Data[2]] then
TeleportService:TeleportToPlaceInstance(game.PlaceId, Message.Data[1], game.Players[Message.Data[2]])
end
end)