How to rejoin a roblox server?
Hey there! My name is @achdef, a programmer and future artist! I decide to teach you how to make a !rejoin command! So let’s get started, please make sure to go in the explanation section to understand with example what is a string!
https://developer.roblox.com/en-us/articles/Variables
https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded
https://developer.roblox.com/en-us/api-reference/event/Player/Chatted
https://developer.roblox.com/en-us/api-reference/class/TeleportService
https://developer.roblox.com/en-us/api-reference/function/TeleportService/Teleport
https://developer.roblox.com/en-us/api-reference/lua-docs/string
I already introduced myself, hihi, but no needs anyways. So. Let’s get started! We will begin to get our Service, seems logic.
So let’s explain it!
The TeleportService is responsible for transporting Players between places and servers.
Teleporting in Roblox describes the transportation of players between different places and servers. TeleportService provides a range of functions related to teleporting single or groups of users to different servers. As Roblox games can contain multiple places, you can use the TeleportService to teleport players between different levels.
Previous iterations of the TeleportService relied on several different functions for each scenario. These have since been combined into a single method, TeleportService:TeleportAsync , which may be used to:
Alright. Now, let’s get when a player join.
Explaining time.
The PlayerAdded event fires when a player enters the game. This is used to fire an event when a player joins a game, such as loading the player’s saved GlobalDataStore data.
This can be used alongside the Players.PlayerRemoving event, which fires when a player is about to leave the game. For instance, if you would like print a message every time a new player joins or leaves the game:
If you want to track when a player’s character is added or removed from the game, such as when a player respawns or dies, you can use the Player.CharacterAdded and Player.CharacterRemoving functions.
Alright, I need to admit I copy and paste it from the DevHub. But anyways, now we want to get when the player chatted!
The Chatted event fires when a Player types a message and presses enter in Roblox’s provided chat bar. This is done using some Lua bindings by the default chat script. You can prevent players from chatting by using StarterGui:SetCoreGuiEnabled and disabling the Chat CoreGuiType .
Using this event and some string manipulation functions like string.sub and string.lower , it is possible to create chat commands, even with arguments like player names. Usually, commands are prefixed such as /heal PlayerName . To check for a prefix in a string, use string.sub on the message to check a substring of the message: string.sub(message, 1, 6) == "/heal " (note the inclusion of the space) . Then, extract the rest of the command using string.sub again: string.sub(message, 7) will be equal to the player name. Check if that player exists, and if so, perform the command’s action (in this example, healing them). Check the code samples for examples of chat commands.
The message text fired with this event is unfiltered . If you are displaying player input like chat to other players in any form, it must be filtered using Chat:FilterStringAsync . Keep this in mind when creating your own chat systems; if your game does not properly filter chat it may have moderation action taken against it.
Now, let’s move on on to what will it’s do? We will get a string and make it lowercases. In this way I could say !REJoin without any problems.
if is a statement. string.lower is a bit different. So we get our string. (string) and then make it lowercases. (string.lower), and the brackets is for define our function name so msg. then is also a statement.
Now, teleporting our user! We will get our Service for that and then use the :Teleport() function!
teleportToPlace if you remember is our variable to get the TeleportService, the :Teleport function’s job is to teleport the player with the arguments filled in. The first argument is our PlaceId, so game.PlaceId and the second is plr. We seperate it with a ,.