Basically I am working on an admin script, this is originally based off of AlvinBlox's tutorial: click here
I am trying to add the 'me' shortcut, so that if the script sees that the first argument is 'me' it sets the player to do the command on variable to the person that originally made the command get executed. It isn't working, but it works when I change the argument where the player name to do the command on to the full username, I am having the issue on both line 67 and line 108 , here is my code:
local commands = {}
local admins = {
"HauntedDestroyer";
"AwesomeJackmate";
"FestiveDanl";
"vextrixis";
"farhanzafar"
}
local prefix = "/"
local function findPlayer(name) --name is string
for _, 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) --player is object
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
commands.tp = 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 arguments[1] == "me" then
plrToTP = findPlayer(sender.Name)
print(sender.Name)
elseif arguments[2] == "me" then
plrToTPTo = findPlayer(sender.Name)
end
if plrToTP and plrToTPTo then
plrToTP.Character.HumanoidRootPart.CFrame = plrToTPTo.Character.HumanoidRootPart.CFrame
print("tp successful lol")
end
end
end
commands.speed = function(sender, arguments)
local playerToGiveSpeedTo = arguments[1]
local amountOfSpeedToGive = arguments[2]
if playerToGiveSpeedTo then
local plr = nil
if arguments[1] == "me" then
plr = findPlayer(sender.Name)
print(sender.Name)
else
plr = findPlayer(playerToGiveSpeedTo)
end
if plr then
plr.Character.Humanoid.WalkSpeed = tonumber(amountOfSpeedToGive)
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
end)
end)

3 comments
Thank you, mostly everything works fine, except the part in speed to set the walkspeed (line 43), I'm not sure why this is happening, as I said before the tp works perfectly, it's just that the speed does not work either by typing 'me' or your username. The error I get is that it attempted to index nil with humanoid.
plr.Character = v.Character - 43.
plr.Character to v.Character Line 43.