Admin script help

hey im making a tp command
local commands = {}

local admins = {
“justhatsav”;
“pcmrdann2003”
}

local prefix = “'”

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.tp = function(sender, arguments)

print("TP Funtion fired by"..sender.Name)

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("successfully moved")
	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
end

it doesnt seem to work any help is great

Hi!

The following script should work. I’m a bit in a hurry at the moment, so you may potentially be able to find an exception while using the script. My tests brought up some positive results, however. I don’t exactly know where the original problem was. Hope you don’t mind me changing some things a little bit. At the first glance the script looks different, but in fact differs only slightly and code execution steps are the same. Previously, the script contained an array of all admins, which is now replaced with a dictionary, because it seems fast and shortens the code a little bit. Unfortunately, I didn’t quite catch the purpose of prefix (short on time right now), so I used string.sub. You can always change that later. Lastly, player.Chatted really returns two parameters (message and recipient), although the recipient is only defined if message is sent privately to another player (whispered).

I will edit this when I can!

--- Settings ----------------
local admins = {
	["justhatsav"] = true;
	["pcmrdann2003"] = true;
}
local prefix = "'" -- not yet used
-----------------------------

local Players = game:GetService("Players")

local commands = {}

local function findPlayer(name)
	for i, player in pairs(Players:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player
		end
	end
	return nil
end

commands.tp = function(sender, arguments)
	print("TP Function fired by"..sender.Name)
	
	if #arguments > 2 then
		for i, playerName in findPlayer(arguments) do
			print(playerName)
		end
	end
	
	local playerToTP = findPlayer(arguments[1])
	local locatorPlayer = findPlayer(arguments[2])
	
	if playerToTP and locatorPlayer then
		playerToTP.Character.HumanoidRootPart.CFrame = locatorPlayer.Character.HumanoidRootPart.CFrame
		print("Successfully moved")
	end
end

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if admins[player.Name] then
			message = string.lower(message)
			
			message = message:split(" ")
			local slashCommand = message[1]
			
			local cmd; local cmdValidation = function(slashCommand)
				if string.sub(slashCommand, 1, 1) == "/" then
					-- get the rest of the string, "slash" excluded
					return string.sub(slashCommand, 2, #slashCommand)
				end
			end
			cmd = cmdValidation(slashCommand)
			
			if commands[cmd] then
				local arguments = {}
				for i = 2, #message, 1 do
					table.insert(arguments, message[i])
				end
				commands[cmd](player, arguments)
			end
		end
	end)
end)

ill try it out thanks! :smiley: