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

Why is my admin command script not behaving the way it should be?

Asked by 5 years ago

For my game, I am trying to make an admin command. Specifically, a command that can change anybody's speed. For now, FE is disabled to see if that was what was causing the script to not work. I tried following this this guide and either I didn't follow it correctly or it's outdated in which I doubt.

Code:

local Admins = {
    "TheOriginalJackie58";
    "BennyBoiOriginal";
}

local function IsAdmin(Player)
    for _,Admin in pairs (Admins) do
        print(Admin,Player)
        if type(Admin) == "string" and string.lower(Admin) == string.lower(Player.Name) then
            return true
        end
    end
    return false
end

local function getPlayerFromName(name)
   for _, player in pairs(game:GetService("Players"):GetPlayers()) do
      if player.Name:lower() == name:lower() then
          return player
      end
   end
end

local function increasePlrSpeed(target, speed)
    if target.Character.Humanoid.Heath == 0 then return false end
    target.Character.Humanoid.WalkSpeed = speed
    return true
end

local function Run(ChatService)

    local function processMessage(speakerName, messageObject, channelName)
        local messageText = messageObject.Message
        local isACommand = string.find(messageText, ";speed")
        if not isACommand then return false end
        local speaker = ChatService:GetSpeaker(speakerName)
        local speakerplr = speaker:GetPlayer()
        if not IsAdmin(speakerplr) then return false end

        local Arguments = {}

        for Argument in string.gmatch(messageText,"[^%s]+") do
            table.insert(Arguments,Argument)
        end
        table.remove(Arguments,1)

        local target = Arguments[1] -- Getting the first argument which is the player name
        local targetplr = getPlayerFromName(target) -- Getting the target player from a string

        local success = increasePlrSpeed(targetplr, Arguments[2]) -- calling the speed function with parameters targetplr and desired speed
        return success

    end

    ChatService:RegisterProcessCommandsFunction("speed_command", processMessage)

end

return Run
0
Which part doesn't work? Amiaa16 3227 — 5y
0
When I type the command it chat it doesn't do anything and the message gets sent to the server instead if getting blocked. BennyBoiOriginal 293 — 5y

Answer this question