I would like to make when I type in chat :tele JadtrugamingYT1
game.Players.JadtrugamingYT1.Chatted:Connect(function(message)
local array = string.split(message," ")
if array[1] == ":tele" then
local playerTo = game.Players:FindFirstChild(array[2])
local characterFrom = game.Players.JadtrugamingYT1.Character
characterFrom.HumanoidRootPart.CFrame = playerTo.Character.HumanoidRootPart.CFrame
end
end)
idk if this is the best way to do it buts it’s the one i thought of
I’ve actually already made an admin system for myself! Let me show you what I have for a command. This allows for partial names for teleportation.
local AdminList = {"benpinpop"}
local function CheckAdmin(plr)
for i,v in pairs(AdminList) do
if plr:lower() == v then
return true
else
return false
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
local IsAdmin = CheckAdmin(plr.Name)
plr.Chatted:Connect(function(Command)
if IsAdmin == true then
local CommandInfo = string.split(Command," ")
if CommandInfo[1]:lower() == "to" then
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#CommandInfo[2]) == CommandInfo[2]:lower() then
local PlrToTeleportTo = v.Character
plr.Character.HumanoidRootPart.CFrame = PlrToTeleportTo.HumanoidRootPart.CFrame * CFrame.new(0,0,-4) * CFrame.Angles(0,math.rad(180),0)
end
end
elseif CommandInfo[1]:lower() == "bring" then
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#CommandInfo[2]) == CommandInfo[2]:lower() then
local PlrToTeleportTo = v.Character
PlrToTeleportTo.HumanoidRootPart.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-4) * CFrame.Angles(0,math.rad(180),0)
end
end
end
end
end)
end)
Not a good idea, it’d error every time a player joins the server, just have an check admin for loop and return system setup. Then check if your admin variable is equal to true.
Fun advice, you’ll get better performance if you use the index method for the string library
For example
local string_lower = string.lower
String:lower() <-- Slow
string.lower(String) <-- Faster
string_lower(String) <-- Fastest
I believe this is how. Simply chat “:tele [your username] [ their username]”
local commands = {}
local prefix = ":"
local admins = {
"JadtrugamingYT1";
}
local function FindPlayer(Name)
for i, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == Name then
return player
end
end
return nil
end
local function isAdmin(player)
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
commands.tele = function(sender, arguments)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleportName = arguments[1]
local playerToTeleportToName = arguments[2]
if playerToTeleportName and playerToTeleportToName then
local plrToTp = FindPlayer(playerToTeleportName)
local plrToTpTo = FindPlayer(playerToTeleportToName)
if plrToTp and plrToTpTo then
plrToTp.Character.HumanoidRootPart.CFrame = plrToTpTo.Character.HumanoidRootPart.CFrame
print("The deed is done...")
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, recipient)
if isAdmin(player) then
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local arguments = {}
for i = 2, #splitString, 1 do
table.insert(arguments, splitString[i])
end
commands[cmdName](player, arguments)
end
else
print("not admin...sorry!")
end
end)
end)
I was posting the method, not that you should actually copy and paste the code. If you were to put it in a game you would obviously hook it up to a playerAdded event and then check for admin.
what? the “:” is not an operator for string
, also it’s string
not String
these are the exact same thing
game.Players.PlayerAdded:Connect(function(Plr)
Plr.Chatted:Connect(function(Msg, Recipient)
if Recipient then return end -- If you want the cmd to work in private chat, remove this line
local SplitMsg = string.split(Msg, " ")
local Cmd = SplitMsg[1]
Cmd = string.lower(Cmd)
if Cmd == ":tele" then
for _, v in pairs(game.Players:GetPlayers()) do
if string.find(v.Name, SplitMsg[2]) then
local Char = v.Character or v.CharacterAdded:Wait()
Char.HumanoidRootPart.Position = Plr.Character.Position
end
end)
end)
No they’re not the same
Here let me retype it because I was on phone when I did it
local string_lower = string.lower
("YEET"):lower() <-- Slow
string.lower("YEET") <-- Faster
string_lower("YEET") <-- Fastest
I did capital String to show it wasn’t string, so yes I do know that it is string
again, this is nothing, if you tried printing this you would get an error
and these two are still exactly the same
No they are not, in the luau optimizations and actual VM itself, localizing your string.lower and calling that has less OP calls than if you keep calling string.lower separately
and sorry this wont error
("YEET"):lower()
It was just to show that which is faster and slower
okay even if that’s true, ("YEET"):lower()
is still nothing. explain to me how this won’t error
print("YEET":lower())
Did you even see my above post I corrected myself
print(("YEET"):lower())
And yes it is factually true.
ah I see, yes I saw your post but I didn’t understand it right away. Thank you for explaining