Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I can't get the 'me' shortcut in my admin script to work, how can I do this correctly?

Asked by 4 years ago
Edited 4 years ago

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)

1 answer

Log in to vote
1
Answered by
9mze 193
4 years ago

Changed your findPlayer function so it sends a list instead. Added sender to the function so it's easier to know who made the command. Had to change your tp and speed a little so it matches the function.

local function findPlayer(sender, name) --name is string
    local list = {}
    if name:lower() == "me" then
        table.insert(list, sender)
    elseif name:lower() == "all" then
        list = game.Players:GetPlayers()
    else
        for _, v in pairs(game.Players:GetPlayers()) do
            if v.Name:sub(1, name:len()):lower() == name:lower() then
                table.insert(list, v)
            end
        end
    end
    return list
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(sender, playerToTeleportName)
        local plrToTPTo = findPlayer(sender, playerToTeleportToName)

        for _, totp in pairs(plrToTP) do
            for _, tpto in pairs(plrToTPTo) do
                totp.Character.HumanoidRootPart.CFrame = tpto.Character.HumanoidRootPart.CFrame
            end
        end
    end
end

commands.speed = function(sender, arguments)
    local playerToGiveSpeedTo = arguments[1]
    local amountOfSpeedToGive = arguments[2]

    if playerToGiveSpeedTo then
        local plr = findPlayer(sender, playerToGiveSpeedTo)
        for _, v in pairs(plr) do
            plr.Character.Humanoid.WalkSpeed = tonumber(amountOfSpeedToGive)
        end
    end
end
0
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. HauntedDestroyer 106 — 4y
0
plr.Character = v.Character - 43. 9mze 193 — 4y
0
plr.Character to v.Character Line 43. 9mze 193 — 4y
Ad

Answer this question