How to make a Join User command! | Tutorial

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)
32 Likes

Could you make a video demonstrating this

And thanks for the tutorial

3 Likes

Just format this
Anyway nice tutorial

1 Like

Great tutorial.

I didn’t know that you could make a chat command for this, but do you mind explaining the code your telling to paste? I want to understand what code I’m pasting so I can learn from it

5 Likes

Yeah I’ll format it lol, don’t know why it did that…

1 Like

Making a video right now, thanks!

1 Like

Quick question,
image
You are checking by UserId and you are implying that you can also check with a username and a custom name right?

Nvm, you are just checking by UserId, I was going to warn that custom names could bypass security since anyone can set a custom name.

1 Like

(I commented on every part that I changed)

So you can put add usernames to the table yea, but the comments are just to show what the UserId is. To make it use usernames, put only usernames in the table and edit that script to be:

local Commands = {}
local Prefix = "/"

local Admins = { -- The usernames aren't as good of a check because a user can change their username.
	"WestJordan08", -- These names to not need to be capitalized!
    "Roblox",
    "Builderman"
}

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 string.lower(v) == string.lower(Plr.Name) then -- Checking if the player name is in the table or not when a new player joins.
				
				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)
1 Like

Why using Messaging Service since TeleportService:GetPlayerInstanceAsync() exist
https://create.roblox.com/docs/reference/engine/classes/TeleportService#GetPlayerPlaceInstanceAsync

1 Like

That would work. This is old code and I’ve kinda fallen away from Roblox Development.

Ah okay my bad sorry I didn’t see when it was posted

Also, the system is meant for teleporting between places in a single game. So teleporting between different games isn’t needed.

now you cant teleport between universe i think or you have to enable it.

Hey i am having problems with creating it please respo

Hey, haven’t been here in a while. Can you explain the issues that you are having?

1 Like

It seems not to be working, i can’t find out where exactly you put the modulescripts, scripts etc. I believed that’s the error or that’s the issue on why it won’t worked out. can you please put more information or clear tutorial on setting up the system? Thanks!

Please if you have discord, maybe i could drop mine and we could possibly talk their


I’ll explain here why it got me confusing, The part where you said:

“Then make a script as a child of that and paste this inside”


Im not sure if im correct or not

Those 2 go in every place file. Can you explain what isn’t working please?

Hi! Can you make tutorial for GUI?